2376
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
|
4 2006, 2007 John W. Eaton |
2376
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2376
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
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 |
7064
|
615 octave_value::octave_value (const ArrayN<octave_int8>& inda) |
|
616 : rep (new octave_int8_matrix (inda)) |
|
617 { |
|
618 maybe_mutate (); |
|
619 } |
|
620 |
4901
|
621 octave_value::octave_value (const uint8NDArray& inda) |
|
622 : rep (new octave_uint8_matrix (inda)) |
|
623 { |
|
624 maybe_mutate (); |
|
625 } |
|
626 |
7064
|
627 octave_value::octave_value (const ArrayN<octave_uint8>& inda) |
|
628 : rep (new octave_uint8_matrix (inda)) |
|
629 { |
|
630 maybe_mutate (); |
|
631 } |
|
632 |
4901
|
633 octave_value::octave_value (const int16NDArray& inda) |
|
634 : rep (new octave_int16_matrix (inda)) |
|
635 { |
|
636 maybe_mutate (); |
|
637 } |
|
638 |
7064
|
639 octave_value::octave_value (const ArrayN<octave_int16>& inda) |
|
640 : rep (new octave_int16_matrix (inda)) |
|
641 { |
|
642 maybe_mutate (); |
|
643 } |
|
644 |
4901
|
645 octave_value::octave_value (const uint16NDArray& inda) |
|
646 : rep (new octave_uint16_matrix (inda)) |
|
647 { |
|
648 maybe_mutate (); |
|
649 } |
|
650 |
7064
|
651 octave_value::octave_value (const ArrayN<octave_uint16>& inda) |
|
652 : rep (new octave_uint16_matrix (inda)) |
|
653 { |
|
654 maybe_mutate (); |
|
655 } |
|
656 |
4901
|
657 octave_value::octave_value (const int32NDArray& inda) |
|
658 : rep (new octave_int32_matrix (inda)) |
|
659 { |
|
660 maybe_mutate (); |
|
661 } |
|
662 |
7064
|
663 octave_value::octave_value (const ArrayN<octave_int32>& inda) |
|
664 : rep (new octave_int32_matrix (inda)) |
|
665 { |
|
666 maybe_mutate (); |
|
667 } |
|
668 |
4901
|
669 octave_value::octave_value (const uint32NDArray& inda) |
|
670 : rep (new octave_uint32_matrix (inda)) |
|
671 { |
|
672 maybe_mutate (); |
|
673 } |
|
674 |
7064
|
675 octave_value::octave_value (const ArrayN<octave_uint32>& inda) |
|
676 : rep (new octave_uint32_matrix (inda)) |
|
677 { |
|
678 maybe_mutate (); |
|
679 } |
|
680 |
4901
|
681 octave_value::octave_value (const int64NDArray& inda) |
|
682 : rep (new octave_int64_matrix (inda)) |
|
683 { |
|
684 maybe_mutate (); |
|
685 } |
|
686 |
7064
|
687 octave_value::octave_value (const ArrayN<octave_int64>& inda) |
|
688 : rep (new octave_int64_matrix (inda)) |
|
689 { |
|
690 maybe_mutate (); |
|
691 } |
|
692 |
4901
|
693 octave_value::octave_value (const uint64NDArray& inda) |
|
694 : rep (new octave_uint64_matrix (inda)) |
|
695 { |
|
696 maybe_mutate (); |
|
697 } |
|
698 |
7064
|
699 octave_value::octave_value (const ArrayN<octave_uint64>& inda) |
|
700 : rep (new octave_uint64_matrix (inda)) |
|
701 { |
|
702 maybe_mutate (); |
|
703 } |
|
704 |
2376
|
705 octave_value::octave_value (double base, double limit, double inc) |
2423
|
706 : rep (new octave_range (base, limit, inc)) |
|
707 { |
|
708 maybe_mutate (); |
|
709 } |
2376
|
710 |
|
711 octave_value::octave_value (const Range& r) |
2423
|
712 : rep (new octave_range (r)) |
|
713 { |
|
714 maybe_mutate (); |
|
715 } |
2376
|
716 |
|
717 octave_value::octave_value (const Octave_map& m) |
2825
|
718 : rep (new octave_struct (m)) |
|
719 { |
2880
|
720 } |
|
721 |
4643
|
722 octave_value::octave_value (const streamoff_array& off) |
|
723 : rep (new octave_streamoff (off)) |
|
724 { |
|
725 } |
|
726 |
4587
|
727 octave_value::octave_value (const octave_value_list& l, bool is_csl) |
5477
|
728 : rep (is_csl |
5759
|
729 ? dynamic_cast<octave_base_value *> (new octave_cs_list (l)) |
|
730 : dynamic_cast<octave_base_value *> (new octave_list (l))) |
2880
|
731 { |
|
732 } |
2376
|
733 |
|
734 octave_value::octave_value (octave_value::magic_colon) |
2825
|
735 : rep (new octave_magic_colon ()) |
|
736 { |
|
737 } |
2376
|
738 |
5759
|
739 octave_value::octave_value (octave_base_value *new_rep) |
2825
|
740 : rep (new_rep) |
|
741 { |
|
742 } |
2376
|
743 |
5759
|
744 octave_base_value * |
3933
|
745 octave_value::clone (void) const |
2880
|
746 { |
|
747 panic_impossible (); |
3546
|
748 return 0; |
2880
|
749 } |
|
750 |
2409
|
751 void |
|
752 octave_value::maybe_mutate (void) |
|
753 { |
5759
|
754 octave_base_value *tmp = rep->try_narrowing_conversion (); |
2409
|
755 |
|
756 if (tmp && tmp != rep) |
|
757 { |
|
758 if (--rep->count == 0) |
|
759 delete rep; |
|
760 |
|
761 rep = tmp; |
|
762 } |
|
763 } |
|
764 |
4247
|
765 octave_value |
4271
|
766 octave_value::single_subsref (const std::string& type, |
|
767 const octave_value_list& idx) |
4247
|
768 { |
|
769 std::list<octave_value_list> i; |
|
770 |
|
771 i.push_back (idx); |
|
772 |
|
773 return rep->subsref (type, i); |
|
774 } |
|
775 |
2974
|
776 octave_value_list |
4247
|
777 octave_value::subsref (const std::string& type, |
4219
|
778 const std::list<octave_value_list>& idx, int nargout) |
3933
|
779 { |
|
780 if (is_constant ()) |
|
781 return rep->subsref (type, idx); |
|
782 else |
|
783 return rep->subsref (type, idx, nargout); |
|
784 } |
|
785 |
|
786 octave_value |
4247
|
787 octave_value::next_subsref (const std::string& type, |
4219
|
788 const std::list<octave_value_list>& idx, |
4233
|
789 size_t skip) |
3933
|
790 { |
4582
|
791 if (! error_state && idx.size () > skip) |
3933
|
792 { |
4219
|
793 std::list<octave_value_list> new_idx (idx); |
4233
|
794 for (size_t i = 0; i < skip; i++) |
4219
|
795 new_idx.erase (new_idx.begin ()); |
3933
|
796 return subsref (type.substr (skip), new_idx); |
|
797 } |
|
798 else |
|
799 return *this; |
|
800 } |
|
801 |
|
802 octave_value_list |
4994
|
803 octave_value::next_subsref (int nargout, const std::string& type, |
|
804 const std::list<octave_value_list>& idx, |
|
805 size_t skip) |
|
806 { |
|
807 if (! error_state && idx.size () > skip) |
|
808 { |
|
809 std::list<octave_value_list> new_idx (idx); |
|
810 for (size_t i = 0; i < skip; i++) |
|
811 new_idx.erase (new_idx.begin ()); |
|
812 return subsref (type.substr (skip), new_idx, nargout); |
|
813 } |
|
814 else |
|
815 return *this; |
|
816 } |
|
817 |
|
818 octave_value_list |
3544
|
819 octave_value::do_multi_index_op (int nargout, const octave_value_list& idx) |
2974
|
820 { |
3544
|
821 return rep->do_multi_index_op (nargout, idx); |
2974
|
822 } |
|
823 |
3933
|
824 #if 0 |
3204
|
825 static void |
3933
|
826 gripe_assign_failed (const std::string& on, const std::string& tn1, |
|
827 const std::string& tn2) |
3204
|
828 { |
|
829 error ("assignment failed for `%s %s %s'", |
|
830 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
831 } |
3933
|
832 #endif |
3204
|
833 |
|
834 static void |
3933
|
835 gripe_assign_failed_or_no_method (const std::string& on, |
|
836 const std::string& tn1, |
3523
|
837 const std::string& tn2) |
3204
|
838 { |
|
839 error ("assignment failed, or no method for `%s %s %s'", |
|
840 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
841 } |
|
842 |
3933
|
843 octave_value |
4247
|
844 octave_value::subsasgn (const std::string& type, |
4219
|
845 const std::list<octave_value_list>& idx, |
3933
|
846 const octave_value& rhs) |
|
847 { |
|
848 return rep->subsasgn (type, idx, rhs); |
|
849 } |
|
850 |
|
851 octave_value |
4247
|
852 octave_value::assign (assign_op op, const std::string& type, |
4219
|
853 const std::list<octave_value_list>& idx, |
3933
|
854 const octave_value& rhs) |
|
855 { |
|
856 octave_value retval; |
|
857 |
|
858 make_unique (); |
|
859 |
|
860 octave_value t_rhs = rhs; |
|
861 |
|
862 if (op != op_asn_eq) |
|
863 { |
5775
|
864 // FIXME -- only do the following stuff if we can't find |
3933
|
865 // a specific function to call to handle the op= operation for |
|
866 // the types we have. |
|
867 |
5001
|
868 octave_value t; |
|
869 if (is_constant ()) |
|
870 t = subsref (type, idx); |
|
871 else |
|
872 { |
|
873 octave_value_list tl = subsref (type, idx, 1); |
|
874 if (tl.length () > 0) |
|
875 t = tl(0); |
|
876 } |
3933
|
877 |
|
878 if (! error_state) |
|
879 { |
|
880 binary_op binop = op_eq_to_binary_op (op); |
|
881 |
|
882 if (! error_state) |
|
883 t_rhs = do_binary_op (binop, t, rhs); |
|
884 } |
|
885 } |
|
886 |
|
887 if (! error_state) |
|
888 { |
|
889 if (type[0] == '.' && ! is_map ()) |
|
890 { |
|
891 octave_value tmp = Octave_map (); |
|
892 retval = tmp.subsasgn (type, idx, t_rhs); |
|
893 } |
|
894 else |
|
895 retval = subsasgn (type, idx, t_rhs); |
|
896 } |
|
897 |
|
898 if (error_state) |
|
899 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
900 type_name (), rhs.type_name ()); |
|
901 |
|
902 return retval; |
|
903 } |
|
904 |
|
905 const octave_value& |
3203
|
906 octave_value::assign (assign_op op, const octave_value& rhs) |
2880
|
907 { |
3533
|
908 if (op == op_asn_eq) |
3203
|
909 operator = (rhs); |
|
910 else |
|
911 { |
5775
|
912 // FIXME -- only do the following stuff if we can't find |
3204
|
913 // a specific function to call to handle the op= operation for |
|
914 // the types we have. |
|
915 |
|
916 binary_op binop = op_eq_to_binary_op (op); |
|
917 |
|
918 if (! error_state) |
|
919 { |
|
920 octave_value t = do_binary_op (binop, *this, rhs); |
|
921 |
|
922 if (! error_state) |
|
923 operator = (t); |
|
924 } |
|
925 |
|
926 if (error_state) |
|
927 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
928 type_name (), rhs.type_name ()); |
|
929 } |
|
930 |
3933
|
931 return *this; |
2376
|
932 } |
|
933 |
5275
|
934 octave_idx_type |
4563
|
935 octave_value::length (void) const |
|
936 { |
|
937 int retval = 0; |
|
938 |
|
939 dim_vector dv = dims (); |
4584
|
940 |
4563
|
941 for (int i = 0; i < dv.length (); i++) |
|
942 { |
|
943 if (dv(i) < 0) |
|
944 { |
|
945 retval = -1; |
|
946 break; |
|
947 } |
|
948 |
4584
|
949 if (dv(i) == 0) |
|
950 { |
|
951 retval = 0; |
|
952 break; |
|
953 } |
|
954 |
4563
|
955 if (dv(i) > retval) |
|
956 retval = dv(i); |
|
957 } |
|
958 |
|
959 return retval; |
|
960 } |
|
961 |
5659
|
962 Matrix |
|
963 octave_value::size (void) const |
|
964 { |
|
965 dim_vector dv = dims (); |
|
966 |
|
967 int n_dims = dv.length (); |
|
968 |
|
969 Matrix retval (1, n_dims); |
|
970 |
|
971 while (n_dims--) |
|
972 retval(n_dims) = dv(n_dims); |
|
973 |
|
974 return retval; |
|
975 } |
|
976 |
3351
|
977 Cell |
|
978 octave_value::cell_value (void) const |
|
979 { |
|
980 return rep->cell_value (); |
|
981 } |
|
982 |
2376
|
983 Octave_map |
|
984 octave_value::map_value (void) const |
|
985 { |
|
986 return rep->map_value (); |
|
987 } |
|
988 |
4645
|
989 std::streamoff |
4643
|
990 octave_value::streamoff_value (void) const |
|
991 { |
|
992 return rep->streamoff_value (); |
|
993 } |
|
994 |
4645
|
995 streamoff_array |
|
996 octave_value::streamoff_array_value (void) const |
|
997 { |
|
998 return rep->streamoff_array_value (); |
|
999 } |
|
1000 |
2974
|
1001 octave_function * |
|
1002 octave_value::function_value (bool silent) |
|
1003 { |
|
1004 return rep->function_value (silent); |
|
1005 } |
|
1006 |
4700
|
1007 octave_user_function * |
|
1008 octave_value::user_function_value (bool silent) |
|
1009 { |
|
1010 return rep->user_function_value (silent); |
|
1011 } |
|
1012 |
4346
|
1013 octave_fcn_handle * |
4343
|
1014 octave_value::fcn_handle_value (bool silent) |
|
1015 { |
|
1016 return rep->fcn_handle_value (silent); |
|
1017 } |
|
1018 |
4933
|
1019 octave_fcn_inline * |
|
1020 octave_value::fcn_inline_value (bool silent) |
|
1021 { |
|
1022 return rep->fcn_inline_value (silent); |
|
1023 } |
|
1024 |
2880
|
1025 octave_value_list |
|
1026 octave_value::list_value (void) const |
|
1027 { |
|
1028 return rep->list_value (); |
|
1029 } |
|
1030 |
2376
|
1031 ColumnVector |
3419
|
1032 octave_value::column_vector_value (bool force_string_conv, |
4661
|
1033 bool /* frc_vec_conv */) const |
3419
|
1034 { |
|
1035 ColumnVector retval; |
|
1036 |
|
1037 Matrix m = matrix_value (force_string_conv); |
|
1038 |
|
1039 if (error_state) |
|
1040 return retval; |
|
1041 |
5275
|
1042 octave_idx_type nr = m.rows (); |
|
1043 octave_idx_type nc = m.columns (); |
3419
|
1044 |
|
1045 if (nc == 1) |
|
1046 { |
|
1047 retval.resize (nr); |
5275
|
1048 for (octave_idx_type i = 0; i < nr; i++) |
3419
|
1049 retval (i) = m (i, 0); |
|
1050 } |
|
1051 else |
|
1052 { |
3523
|
1053 std::string tn = type_name (); |
3419
|
1054 gripe_invalid_conversion (tn.c_str (), "real column vector"); |
|
1055 } |
|
1056 |
|
1057 return retval; |
|
1058 } |
|
1059 |
|
1060 ComplexColumnVector |
|
1061 octave_value::complex_column_vector_value (bool force_string_conv, |
4661
|
1062 bool /* frc_vec_conv */) const |
3419
|
1063 { |
|
1064 ComplexColumnVector retval; |
|
1065 |
|
1066 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1067 |
|
1068 if (error_state) |
|
1069 return retval; |
|
1070 |
5275
|
1071 octave_idx_type nr = m.rows (); |
|
1072 octave_idx_type nc = m.columns (); |
3419
|
1073 |
|
1074 if (nc == 1) |
|
1075 { |
3465
|
1076 retval.resize (nr); |
5275
|
1077 for (octave_idx_type i = 0; i < nr; i++) |
3419
|
1078 retval (i) = m (i, 0); |
|
1079 } |
|
1080 else |
|
1081 { |
3523
|
1082 std::string tn = type_name (); |
3419
|
1083 gripe_invalid_conversion (tn.c_str (), "complex column vector"); |
|
1084 } |
|
1085 |
|
1086 return retval; |
|
1087 } |
|
1088 |
|
1089 RowVector |
|
1090 octave_value::row_vector_value (bool force_string_conv, |
4661
|
1091 bool /* frc_vec_conv */) const |
3419
|
1092 { |
|
1093 RowVector retval; |
|
1094 |
|
1095 Matrix m = matrix_value (force_string_conv); |
|
1096 |
|
1097 if (error_state) |
|
1098 return retval; |
|
1099 |
5275
|
1100 octave_idx_type nr = m.rows (); |
|
1101 octave_idx_type nc = m.columns (); |
3419
|
1102 |
|
1103 if (nr == 1) |
|
1104 { |
|
1105 retval.resize (nc); |
5275
|
1106 for (octave_idx_type i = 0; i < nc; i++) |
3419
|
1107 retval (i) = m (0, i); |
|
1108 } |
|
1109 else |
|
1110 { |
3523
|
1111 std::string tn = type_name (); |
3419
|
1112 gripe_invalid_conversion (tn.c_str (), "real row vector"); |
|
1113 } |
|
1114 |
|
1115 return retval; |
|
1116 } |
|
1117 |
|
1118 ComplexRowVector |
|
1119 octave_value::complex_row_vector_value (bool force_string_conv, |
4661
|
1120 bool /* frc_vec_conv */) const |
3419
|
1121 { |
|
1122 ComplexRowVector retval; |
|
1123 |
|
1124 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1125 |
|
1126 if (error_state) |
|
1127 return retval; |
|
1128 |
5275
|
1129 octave_idx_type nr = m.rows (); |
|
1130 octave_idx_type nc = m.columns (); |
3419
|
1131 |
|
1132 if (nr == 1) |
|
1133 { |
|
1134 retval.resize (nc); |
5275
|
1135 for (octave_idx_type i = 0; i < nc; i++) |
3419
|
1136 retval (i) = m (0, i); |
|
1137 } |
|
1138 else |
|
1139 { |
3523
|
1140 std::string tn = type_name (); |
3419
|
1141 gripe_invalid_conversion (tn.c_str (), "complex row vector"); |
|
1142 } |
|
1143 |
|
1144 return retval; |
|
1145 } |
|
1146 |
|
1147 // Sloppy... |
|
1148 |
|
1149 Array<double> |
2376
|
1150 octave_value::vector_value (bool force_string_conv, |
|
1151 bool force_vector_conversion) const |
|
1152 { |
3419
|
1153 Array<double> retval; |
2376
|
1154 |
|
1155 Matrix m = matrix_value (force_string_conv); |
|
1156 |
|
1157 if (error_state) |
|
1158 return retval; |
|
1159 |
5275
|
1160 octave_idx_type nr = m.rows (); |
|
1161 octave_idx_type nc = m.columns (); |
2376
|
1162 |
|
1163 if (nr == 1) |
|
1164 { |
|
1165 retval.resize (nc); |
5275
|
1166 for (octave_idx_type i = 0; i < nc; i++) |
2376
|
1167 retval (i) = m (0, i); |
|
1168 } |
|
1169 else if (nc == 1) |
|
1170 { |
|
1171 retval.resize (nr); |
5275
|
1172 for (octave_idx_type i = 0; i < nr; i++) |
2376
|
1173 retval (i) = m (i, 0); |
|
1174 } |
4455
|
1175 else if (nr > 0 && nc > 0) |
2376
|
1176 { |
5781
|
1177 if (! force_vector_conversion) |
|
1178 gripe_implicit_conversion ("Octave:array-as-vector", |
|
1179 type_name (), "real vector"); |
4455
|
1180 |
2376
|
1181 retval.resize (nr * nc); |
5275
|
1182 octave_idx_type k = 0; |
|
1183 for (octave_idx_type j = 0; j < nc; j++) |
|
1184 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
1185 { |
|
1186 OCTAVE_QUIT; |
|
1187 |
|
1188 retval (k++) = m (i, j); |
|
1189 } |
2376
|
1190 } |
|
1191 else |
|
1192 { |
3523
|
1193 std::string tn = type_name (); |
2376
|
1194 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
1195 } |
|
1196 |
|
1197 return retval; |
|
1198 } |
|
1199 |
4044
|
1200 Array<int> |
|
1201 octave_value::int_vector_value (bool force_string_conv, bool require_int, |
|
1202 bool force_vector_conversion) const |
|
1203 { |
|
1204 Array<int> retval; |
|
1205 |
|
1206 Matrix m = matrix_value (force_string_conv); |
|
1207 |
|
1208 if (error_state) |
|
1209 return retval; |
|
1210 |
5275
|
1211 octave_idx_type nr = m.rows (); |
|
1212 octave_idx_type nc = m.columns (); |
4044
|
1213 |
|
1214 if (nr == 1) |
|
1215 { |
|
1216 retval.resize (nc); |
5275
|
1217 for (octave_idx_type i = 0; i < nc; i++) |
4044
|
1218 { |
4153
|
1219 OCTAVE_QUIT; |
|
1220 |
4044
|
1221 double d = m (0, i); |
|
1222 |
|
1223 if (require_int && D_NINT (d) != d) |
|
1224 { |
|
1225 error ("conversion to integer value failed"); |
|
1226 return retval; |
|
1227 } |
|
1228 |
|
1229 retval (i) = static_cast<int> (d); |
|
1230 } |
|
1231 } |
|
1232 else if (nc == 1) |
|
1233 { |
|
1234 retval.resize (nr); |
5275
|
1235 for (octave_idx_type i = 0; i < nr; i++) |
4044
|
1236 { |
4153
|
1237 OCTAVE_QUIT; |
|
1238 |
4044
|
1239 double d = m (i, 0); |
|
1240 |
|
1241 if (require_int && D_NINT (d) != d) |
|
1242 { |
|
1243 error ("conversion to integer value failed"); |
|
1244 return retval; |
|
1245 } |
|
1246 |
|
1247 retval (i) = static_cast<int> (d); |
|
1248 } |
|
1249 } |
4455
|
1250 else if (nr > 0 && nc > 0) |
4044
|
1251 { |
5781
|
1252 if (! force_vector_conversion) |
|
1253 gripe_implicit_conversion ("Octave:array-as-vector", |
|
1254 type_name (), "real vector"); |
4455
|
1255 |
4044
|
1256 retval.resize (nr * nc); |
5275
|
1257 octave_idx_type k = 0; |
|
1258 for (octave_idx_type j = 0; j < nc; j++) |
4044
|
1259 { |
5275
|
1260 for (octave_idx_type i = 0; i < nr; i++) |
4044
|
1261 { |
4153
|
1262 OCTAVE_QUIT; |
|
1263 |
4044
|
1264 double d = m (i, j); |
|
1265 |
|
1266 if (require_int && D_NINT (d) != d) |
|
1267 { |
|
1268 error ("conversion to integer value failed"); |
|
1269 return retval; |
|
1270 } |
|
1271 |
|
1272 retval (k++) = static_cast<int> (d); |
|
1273 } |
|
1274 } |
|
1275 } |
|
1276 else |
|
1277 { |
|
1278 std::string tn = type_name (); |
|
1279 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
1280 } |
|
1281 |
|
1282 return retval; |
|
1283 } |
|
1284 |
3419
|
1285 Array<Complex> |
2376
|
1286 octave_value::complex_vector_value (bool force_string_conv, |
|
1287 bool force_vector_conversion) const |
|
1288 { |
3419
|
1289 Array<Complex> retval; |
2376
|
1290 |
|
1291 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1292 |
|
1293 if (error_state) |
|
1294 return retval; |
|
1295 |
5275
|
1296 octave_idx_type nr = m.rows (); |
|
1297 octave_idx_type nc = m.columns (); |
2376
|
1298 |
|
1299 if (nr == 1) |
|
1300 { |
|
1301 retval.resize (nc); |
5275
|
1302 for (octave_idx_type i = 0; i < nc; i++) |
4153
|
1303 { |
|
1304 OCTAVE_QUIT; |
|
1305 retval (i) = m (0, i); |
|
1306 } |
2376
|
1307 } |
|
1308 else if (nc == 1) |
|
1309 { |
|
1310 retval.resize (nr); |
5275
|
1311 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
1312 { |
|
1313 OCTAVE_QUIT; |
|
1314 retval (i) = m (i, 0); |
|
1315 } |
2376
|
1316 } |
4455
|
1317 else if (nr > 0 && nc > 0) |
2376
|
1318 { |
5781
|
1319 if (! force_vector_conversion) |
|
1320 gripe_implicit_conversion ("Octave:array-as-vector", |
|
1321 type_name (), "complex vector"); |
4455
|
1322 |
2376
|
1323 retval.resize (nr * nc); |
5275
|
1324 octave_idx_type k = 0; |
|
1325 for (octave_idx_type j = 0; j < nc; j++) |
|
1326 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
1327 { |
|
1328 OCTAVE_QUIT; |
|
1329 retval (k++) = m (i, j); |
|
1330 } |
2376
|
1331 } |
|
1332 else |
|
1333 { |
3523
|
1334 std::string tn = type_name (); |
2376
|
1335 gripe_invalid_conversion (tn.c_str (), "complex vector"); |
|
1336 } |
|
1337 |
|
1338 return retval; |
|
1339 } |
|
1340 |
4944
|
1341 int |
|
1342 octave_value::write (octave_stream& os, int block_size, |
|
1343 oct_data_conv::data_type output_type, int skip, |
|
1344 oct_mach_info::float_format flt_fmt) const |
|
1345 { |
|
1346 return rep->write (os, block_size, output_type, skip, flt_fmt); |
|
1347 } |
|
1348 |
2413
|
1349 static void |
3933
|
1350 gripe_binary_op (const std::string& on, const std::string& tn1, |
|
1351 const std::string& tn2) |
2376
|
1352 { |
2903
|
1353 error ("binary operator `%s' not implemented for `%s' by `%s' operations", |
2376
|
1354 on.c_str (), tn1.c_str (), tn2.c_str ()); |
|
1355 } |
|
1356 |
3203
|
1357 static void |
3523
|
1358 gripe_binary_op_conv (const std::string& on) |
3203
|
1359 { |
|
1360 error ("type conversion failed for binary operator `%s'", on.c_str ()); |
|
1361 } |
|
1362 |
2376
|
1363 octave_value |
3933
|
1364 do_binary_op (octave_value::binary_op op, |
|
1365 const octave_value& v1, const octave_value& v2) |
2376
|
1366 { |
|
1367 octave_value retval; |
|
1368 |
|
1369 int t1 = v1.type_id (); |
|
1370 int t2 = v2.type_id (); |
|
1371 |
5759
|
1372 octave_value_typeinfo::binary_op_fcn f |
|
1373 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1374 |
|
1375 if (f) |
|
1376 retval = f (*v1.rep, *v2.rep); |
|
1377 else |
|
1378 { |
|
1379 octave_value tv1; |
5759
|
1380 octave_base_value::type_conv_fcn cf1 = v1.numeric_conversion_function (); |
2376
|
1381 |
|
1382 if (cf1) |
|
1383 { |
5759
|
1384 octave_base_value *tmp = cf1 (*v1.rep); |
3203
|
1385 |
|
1386 if (tmp) |
|
1387 { |
|
1388 tv1 = octave_value (tmp); |
|
1389 t1 = tv1.type_id (); |
|
1390 } |
|
1391 else |
|
1392 { |
|
1393 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1394 return retval; |
|
1395 } |
2376
|
1396 } |
|
1397 else |
|
1398 tv1 = v1; |
|
1399 |
|
1400 octave_value tv2; |
5759
|
1401 octave_base_value::type_conv_fcn cf2 = v2.numeric_conversion_function (); |
2376
|
1402 |
|
1403 if (cf2) |
|
1404 { |
5759
|
1405 octave_base_value *tmp = cf2 (*v2.rep); |
3203
|
1406 |
|
1407 if (tmp) |
|
1408 { |
|
1409 tv2 = octave_value (tmp); |
|
1410 t2 = tv2.type_id (); |
|
1411 } |
|
1412 else |
|
1413 { |
|
1414 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1415 return retval; |
|
1416 } |
2376
|
1417 } |
|
1418 else |
|
1419 tv2 = v2; |
|
1420 |
|
1421 if (cf1 || cf2) |
|
1422 { |
4587
|
1423 f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1424 |
|
1425 if (f) |
|
1426 retval = f (*tv1.rep, *tv2.rep); |
|
1427 else |
|
1428 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1429 v1.type_name (), v2.type_name ()); |
|
1430 } |
|
1431 else |
|
1432 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1433 v1.type_name (), v2.type_name ()); |
|
1434 } |
|
1435 |
|
1436 return retval; |
|
1437 } |
|
1438 |
4915
|
1439 static void |
|
1440 gripe_cat_op (const std::string& tn1, const std::string& tn2) |
|
1441 { |
|
1442 error ("concatenation operator not implemented for `%s' by `%s' operations", |
|
1443 tn1.c_str (), tn2.c_str ()); |
|
1444 } |
|
1445 |
|
1446 static void |
|
1447 gripe_cat_op_conv (void) |
|
1448 { |
|
1449 error ("type conversion failed for concatenation operator"); |
|
1450 } |
|
1451 |
|
1452 octave_value |
|
1453 do_cat_op (const octave_value& v1, const octave_value& v2, |
6867
|
1454 const Array<octave_idx_type>& ra_idx) |
4915
|
1455 { |
|
1456 octave_value retval; |
|
1457 |
5164
|
1458 // Rapid return for concatenation with an empty object. Dimension |
|
1459 // checking handled elsewhere. |
|
1460 if (v1.all_zero_dims ()) |
|
1461 return v2; |
|
1462 if (v2.all_zero_dims ()) |
|
1463 return v1; |
|
1464 |
4915
|
1465 int t1 = v1.type_id (); |
|
1466 int t2 = v2.type_id (); |
|
1467 |
5759
|
1468 octave_value_typeinfo::cat_op_fcn f |
|
1469 = octave_value_typeinfo::lookup_cat_op (t1, t2); |
4915
|
1470 |
|
1471 if (f) |
|
1472 retval = f (*v1.rep, *v2.rep, ra_idx); |
|
1473 else |
|
1474 { |
|
1475 octave_value tv1; |
5759
|
1476 octave_base_value::type_conv_fcn cf1 = v1.numeric_conversion_function (); |
4915
|
1477 |
|
1478 if (cf1) |
|
1479 { |
5759
|
1480 octave_base_value *tmp = cf1 (*v1.rep); |
4915
|
1481 |
|
1482 if (tmp) |
|
1483 { |
|
1484 tv1 = octave_value (tmp); |
|
1485 t1 = tv1.type_id (); |
|
1486 } |
|
1487 else |
|
1488 { |
|
1489 gripe_cat_op_conv (); |
|
1490 return retval; |
|
1491 } |
|
1492 } |
|
1493 else |
|
1494 tv1 = v1; |
|
1495 |
|
1496 octave_value tv2; |
5759
|
1497 octave_base_value::type_conv_fcn cf2 = v2.numeric_conversion_function (); |
4915
|
1498 |
|
1499 if (cf2) |
|
1500 { |
5759
|
1501 octave_base_value *tmp = cf2 (*v2.rep); |
4915
|
1502 |
|
1503 if (tmp) |
|
1504 { |
|
1505 tv2 = octave_value (tmp); |
|
1506 t2 = tv2.type_id (); |
|
1507 } |
|
1508 else |
|
1509 { |
|
1510 gripe_cat_op_conv (); |
|
1511 return retval; |
|
1512 } |
|
1513 } |
|
1514 else |
|
1515 tv2 = v2; |
|
1516 |
|
1517 if (cf1 || cf2) |
|
1518 { |
|
1519 f = octave_value_typeinfo::lookup_cat_op (t1, t2); |
|
1520 |
|
1521 if (f) |
|
1522 retval = f (*tv1.rep, *tv2.rep, ra_idx); |
|
1523 else |
|
1524 gripe_cat_op (v1.type_name (), v2.type_name ()); |
|
1525 } |
|
1526 else |
|
1527 gripe_cat_op (v1.type_name (), v2.type_name ()); |
|
1528 } |
|
1529 |
|
1530 return retval; |
|
1531 } |
|
1532 |
3933
|
1533 void |
|
1534 octave_value::print_info (std::ostream& os, const std::string& prefix) const |
|
1535 { |
|
1536 os << prefix << "type_name: " << type_name () << "\n" |
|
1537 << prefix << "count: " << get_count () << "\n" |
|
1538 << prefix << "rep info: "; |
|
1539 |
|
1540 rep->print_info (os, prefix + " "); |
|
1541 } |
|
1542 |
3203
|
1543 static void |
3523
|
1544 gripe_unary_op (const std::string& on, const std::string& tn) |
3203
|
1545 { |
|
1546 error ("unary operator `%s' not implemented for `%s' operands", |
|
1547 on.c_str (), tn.c_str ()); |
|
1548 } |
|
1549 |
|
1550 static void |
3523
|
1551 gripe_unary_op_conv (const std::string& on) |
3203
|
1552 { |
|
1553 error ("type conversion failed for unary operator `%s'", on.c_str ()); |
|
1554 } |
|
1555 |
|
1556 octave_value |
|
1557 do_unary_op (octave_value::unary_op op, const octave_value& v) |
|
1558 { |
|
1559 octave_value retval; |
|
1560 |
|
1561 int t = v.type_id (); |
|
1562 |
5759
|
1563 octave_value_typeinfo::unary_op_fcn f |
|
1564 = octave_value_typeinfo::lookup_unary_op (op, t); |
3203
|
1565 |
|
1566 if (f) |
|
1567 retval = f (*v.rep); |
|
1568 else |
|
1569 { |
|
1570 octave_value tv; |
5759
|
1571 octave_base_value::type_conv_fcn cf = v.numeric_conversion_function (); |
3203
|
1572 |
|
1573 if (cf) |
|
1574 { |
5759
|
1575 octave_base_value *tmp = cf (*v.rep); |
3203
|
1576 |
|
1577 if (tmp) |
|
1578 { |
|
1579 tv = octave_value (tmp); |
|
1580 t = tv.type_id (); |
|
1581 |
4587
|
1582 f = octave_value_typeinfo::lookup_unary_op (op, t); |
3203
|
1583 |
|
1584 if (f) |
|
1585 retval = f (*tv.rep); |
|
1586 else |
|
1587 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1588 v.type_name ()); |
|
1589 } |
|
1590 else |
|
1591 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
|
1592 } |
|
1593 else |
|
1594 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1595 v.type_name ()); |
|
1596 } |
|
1597 |
|
1598 return retval; |
|
1599 } |
|
1600 |
|
1601 static void |
3933
|
1602 gripe_unary_op_conversion_failed (const std::string& op, |
|
1603 const std::string& tn) |
3203
|
1604 { |
|
1605 error ("operator %s: type conversion for `%s' failed", |
|
1606 op.c_str (), tn.c_str ()); |
|
1607 } |
|
1608 |
3933
|
1609 const octave_value& |
|
1610 octave_value::do_non_const_unary_op (unary_op op) |
3203
|
1611 { |
|
1612 octave_value retval; |
|
1613 |
|
1614 int t = type_id (); |
|
1615 |
5759
|
1616 octave_value_typeinfo::non_const_unary_op_fcn f |
3203
|
1617 = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1618 |
|
1619 if (f) |
|
1620 { |
|
1621 make_unique (); |
|
1622 |
|
1623 f (*rep); |
|
1624 } |
|
1625 else |
|
1626 { |
5759
|
1627 octave_base_value::type_conv_fcn cf = numeric_conversion_function (); |
3203
|
1628 |
|
1629 if (cf) |
|
1630 { |
5759
|
1631 octave_base_value *tmp = cf (*rep); |
3203
|
1632 |
|
1633 if (tmp) |
|
1634 { |
5759
|
1635 octave_base_value *old_rep = rep; |
3203
|
1636 rep = tmp; |
|
1637 |
|
1638 t = type_id (); |
|
1639 |
|
1640 f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1641 |
|
1642 if (f) |
|
1643 { |
|
1644 f (*rep); |
|
1645 |
|
1646 if (old_rep && --old_rep->count == 0) |
|
1647 delete old_rep; |
|
1648 } |
|
1649 else |
|
1650 { |
|
1651 if (old_rep) |
|
1652 { |
|
1653 if (--rep->count == 0) |
|
1654 delete rep; |
|
1655 |
|
1656 rep = old_rep; |
|
1657 } |
|
1658 |
|
1659 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1660 type_name ()); |
|
1661 } |
|
1662 } |
|
1663 else |
|
1664 gripe_unary_op_conversion_failed |
|
1665 (octave_value::unary_op_as_string (op), type_name ()); |
|
1666 } |
|
1667 else |
|
1668 gripe_unary_op (octave_value::unary_op_as_string (op), type_name ()); |
|
1669 } |
3933
|
1670 |
|
1671 return *this; |
3203
|
1672 } |
|
1673 |
3933
|
1674 #if 0 |
3205
|
1675 static void |
3933
|
1676 gripe_unary_op_failed_or_no_method (const std::string& on, |
|
1677 const std::string& tn) |
3205
|
1678 { |
|
1679 error ("operator %s: no method, or unable to evaluate for %s operand", |
|
1680 on.c_str (), tn.c_str ()); |
|
1681 } |
3933
|
1682 #endif |
3205
|
1683 |
|
1684 void |
4661
|
1685 octave_value::do_non_const_unary_op (unary_op, const octave_value_list&) |
3205
|
1686 { |
3933
|
1687 abort (); |
|
1688 } |
|
1689 |
|
1690 octave_value |
4247
|
1691 octave_value::do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
1692 const std::list<octave_value_list>& idx) |
3933
|
1693 { |
|
1694 octave_value retval; |
|
1695 |
|
1696 if (idx.empty ()) |
|
1697 { |
|
1698 do_non_const_unary_op (op); |
3205
|
1699 |
3933
|
1700 retval = *this; |
|
1701 } |
|
1702 else |
|
1703 { |
5775
|
1704 // FIXME -- only do the following stuff if we can't find a |
3933
|
1705 // specific function to call to handle the op= operation for the |
|
1706 // types we have. |
3205
|
1707 |
3933
|
1708 assign_op assop = unary_op_to_assign_op (op); |
|
1709 |
|
1710 retval = assign (assop, type, idx, 1.0); |
|
1711 } |
|
1712 |
|
1713 return retval; |
3205
|
1714 } |
|
1715 |
|
1716 octave_value::assign_op |
|
1717 octave_value::unary_op_to_assign_op (unary_op op) |
|
1718 { |
|
1719 assign_op binop = unknown_assign_op; |
|
1720 |
|
1721 switch (op) |
|
1722 { |
3533
|
1723 case op_incr: |
|
1724 binop = op_add_eq; |
3205
|
1725 break; |
|
1726 |
3533
|
1727 case op_decr: |
|
1728 binop = op_sub_eq; |
3205
|
1729 break; |
|
1730 |
|
1731 default: |
|
1732 { |
3523
|
1733 std::string on = unary_op_as_string (op); |
3205
|
1734 error ("operator %s: no assign operator found", on.c_str ()); |
|
1735 } |
|
1736 } |
|
1737 |
|
1738 return binop; |
|
1739 } |
|
1740 |
3204
|
1741 octave_value::binary_op |
|
1742 octave_value::op_eq_to_binary_op (assign_op op) |
|
1743 { |
|
1744 binary_op binop = unknown_binary_op; |
|
1745 |
|
1746 switch (op) |
|
1747 { |
3533
|
1748 case op_add_eq: |
|
1749 binop = op_add; |
3204
|
1750 break; |
|
1751 |
3533
|
1752 case op_sub_eq: |
|
1753 binop = op_sub; |
3204
|
1754 break; |
|
1755 |
3533
|
1756 case op_mul_eq: |
|
1757 binop = op_mul; |
3204
|
1758 break; |
|
1759 |
3533
|
1760 case op_div_eq: |
|
1761 binop = op_div; |
3204
|
1762 break; |
|
1763 |
3533
|
1764 case op_ldiv_eq: |
|
1765 binop = op_ldiv; |
3204
|
1766 break; |
|
1767 |
4018
|
1768 case op_pow_eq: |
|
1769 binop = op_pow; |
|
1770 break; |
|
1771 |
3533
|
1772 case op_lshift_eq: |
|
1773 binop = op_lshift; |
3204
|
1774 break; |
|
1775 |
3533
|
1776 case op_rshift_eq: |
|
1777 binop = op_rshift; |
3204
|
1778 break; |
|
1779 |
3533
|
1780 case op_el_mul_eq: |
|
1781 binop = op_el_mul; |
3204
|
1782 break; |
|
1783 |
3533
|
1784 case op_el_div_eq: |
|
1785 binop = op_el_div; |
3204
|
1786 break; |
|
1787 |
3533
|
1788 case op_el_ldiv_eq: |
|
1789 binop = op_el_ldiv; |
3204
|
1790 break; |
|
1791 |
4018
|
1792 case op_el_pow_eq: |
|
1793 binop = op_el_pow; |
|
1794 break; |
|
1795 |
3533
|
1796 case op_el_and_eq: |
|
1797 binop = op_el_and; |
3204
|
1798 break; |
|
1799 |
3533
|
1800 case op_el_or_eq: |
|
1801 binop = op_el_or; |
3204
|
1802 break; |
|
1803 |
|
1804 default: |
|
1805 { |
3523
|
1806 std::string on = assign_op_as_string (op); |
3204
|
1807 error ("operator %s: no binary operator found", on.c_str ()); |
|
1808 } |
|
1809 } |
|
1810 |
|
1811 return binop; |
|
1812 } |
|
1813 |
3933
|
1814 octave_value |
|
1815 octave_value::empty_conv (const std::string& type, const octave_value& rhs) |
|
1816 { |
|
1817 octave_value retval; |
|
1818 |
|
1819 if (type.length () > 0) |
|
1820 { |
|
1821 switch (type[0]) |
|
1822 { |
|
1823 case '(': |
|
1824 { |
|
1825 if (type.length () > 1 && type[1] == '.') |
|
1826 retval = Octave_map (); |
|
1827 else |
|
1828 retval = octave_value (rhs.empty_clone ()); |
|
1829 } |
|
1830 break; |
|
1831 |
|
1832 case '{': |
|
1833 retval = Cell (); |
|
1834 break; |
|
1835 |
|
1836 case '.': |
|
1837 retval = Octave_map (); |
|
1838 break; |
|
1839 |
|
1840 default: |
|
1841 panic_impossible (); |
|
1842 } |
|
1843 } |
|
1844 else |
|
1845 retval = octave_value (rhs.empty_clone ()); |
|
1846 |
|
1847 return retval; |
|
1848 } |
|
1849 |
2376
|
1850 void |
|
1851 install_types (void) |
|
1852 { |
|
1853 octave_base_value::register_type (); |
3928
|
1854 octave_cell::register_type (); |
2376
|
1855 octave_scalar::register_type (); |
|
1856 octave_complex::register_type (); |
|
1857 octave_matrix::register_type (); |
|
1858 octave_complex_matrix::register_type (); |
|
1859 octave_range::register_type (); |
2825
|
1860 octave_bool::register_type (); |
|
1861 octave_bool_matrix::register_type (); |
2376
|
1862 octave_char_matrix::register_type (); |
|
1863 octave_char_matrix_str::register_type (); |
5279
|
1864 octave_char_matrix_sq_str::register_type (); |
4901
|
1865 octave_int8_scalar::register_type (); |
|
1866 octave_int16_scalar::register_type (); |
|
1867 octave_int32_scalar::register_type (); |
|
1868 octave_int64_scalar::register_type (); |
|
1869 octave_uint8_scalar::register_type (); |
|
1870 octave_uint16_scalar::register_type (); |
|
1871 octave_uint32_scalar::register_type (); |
|
1872 octave_uint64_scalar::register_type (); |
|
1873 octave_int8_matrix::register_type (); |
|
1874 octave_int16_matrix::register_type (); |
|
1875 octave_int32_matrix::register_type (); |
|
1876 octave_int64_matrix::register_type (); |
|
1877 octave_uint8_matrix::register_type (); |
|
1878 octave_uint16_matrix::register_type (); |
|
1879 octave_uint32_matrix::register_type (); |
|
1880 octave_uint64_matrix::register_type (); |
5164
|
1881 octave_sparse_bool_matrix::register_type (); |
|
1882 octave_sparse_matrix::register_type (); |
|
1883 octave_sparse_complex_matrix::register_type (); |
2376
|
1884 octave_struct::register_type (); |
2880
|
1885 octave_list::register_type (); |
3977
|
1886 octave_cs_list::register_type (); |
2376
|
1887 octave_magic_colon::register_type (); |
2974
|
1888 octave_builtin::register_type (); |
|
1889 octave_mapper::register_type (); |
|
1890 octave_user_function::register_type (); |
4649
|
1891 octave_dld_function::register_type (); |
4643
|
1892 octave_fcn_handle::register_type (); |
4966
|
1893 octave_fcn_inline::register_type (); |
4643
|
1894 octave_streamoff::register_type (); |
2376
|
1895 } |
|
1896 |
4970
|
1897 #if 0 |
|
1898 DEFUN (cast, args, , |
|
1899 "-*- texinfo -*-\n\ |
|
1900 @deftypefn {Built-in Function} {} cast (@var{val}, @var{type})\n\ |
|
1901 Convert @var{val} to the new data type @var{type}.\n\ |
5642
|
1902 @seealso{class, typeinfo}\n\ |
|
1903 @end deftypefn") |
4970
|
1904 { |
|
1905 octave_value retval; |
|
1906 |
|
1907 if (args.length () == 2) |
|
1908 error ("cast: not implemented"); |
|
1909 else |
5823
|
1910 print_usage (); |
4970
|
1911 |
|
1912 return retval; |
|
1913 } |
|
1914 #endif |
|
1915 |
4791
|
1916 DEFUN (sizeof, args, , |
|
1917 "-*- texinfo -*-\n\ |
|
1918 @deftypefn {Built-in Function} {} sizeof (@var{val})\n\ |
|
1919 Return the size of @var{val} in bytes\n\ |
|
1920 @end deftypefn") |
|
1921 { |
|
1922 octave_value retval; |
|
1923 |
|
1924 if (args.length () == 1) |
|
1925 retval = args(0).byte_size (); |
|
1926 else |
5823
|
1927 print_usage (); |
4791
|
1928 |
|
1929 return retval; |
|
1930 } |
|
1931 |
6153
|
1932 static void |
|
1933 decode_subscripts (const char* name, const octave_value& arg, |
|
1934 std::string& type_string, |
|
1935 std::list<octave_value_list>& idx) |
|
1936 { |
|
1937 Octave_map m = arg.map_value (); |
|
1938 |
|
1939 if (! error_state |
6639
|
1940 && m.nfields () == 2 && m.contains ("type") && m.contains ("subs")) |
6153
|
1941 { |
|
1942 Cell& type = m.contents ("type"); |
|
1943 Cell& subs = m.contents ("subs"); |
|
1944 |
|
1945 type_string = std::string (type.length(), '\0'); |
|
1946 |
|
1947 for (int k = 0; k < type.length (); k++) |
|
1948 { |
|
1949 std::string item = type(k).string_value (); |
|
1950 |
|
1951 if (! error_state) |
|
1952 { |
|
1953 if (item == "{}") |
|
1954 type_string[k] = '{'; |
|
1955 else if (item == "()") |
|
1956 type_string[k] = '('; |
|
1957 else if (item == ".") |
|
1958 type_string[k] = '.'; |
|
1959 else |
|
1960 { |
|
1961 error("%s: invalid indexing type `%s'", name, item.c_str ()); |
|
1962 return; |
|
1963 } |
|
1964 } |
|
1965 else |
|
1966 { |
|
1967 error ("%s: expecting type(%d) to be a character string", |
|
1968 name, k+1); |
|
1969 return; |
|
1970 } |
|
1971 |
|
1972 octave_value_list idx_item; |
|
1973 |
|
1974 if (subs(k).is_string ()) |
|
1975 idx_item(0) = subs(k); |
|
1976 else if (subs(k).is_cell ()) |
|
1977 { |
|
1978 Cell subs_cell = subs(k).cell_value (); |
|
1979 |
|
1980 for (int n = 0; n < subs_cell.length (); n++) |
|
1981 { |
|
1982 if (subs_cell(n).is_string () |
|
1983 && subs_cell(n).string_value () == ":") |
|
1984 idx_item(n) = octave_value(octave_value::magic_colon_t); |
|
1985 else |
|
1986 idx_item(n) = subs_cell(n); |
|
1987 } |
|
1988 } |
|
1989 else |
|
1990 { |
|
1991 error ("%s: expecting subs(%d) to be a character string or cell array", |
|
1992 name, k+1); |
|
1993 return; |
|
1994 } |
|
1995 |
|
1996 idx.push_back (idx_item); |
|
1997 } |
|
1998 } |
|
1999 else |
|
2000 error ("%s: second argument must be a structure with fields `type' and `subs'", name); |
|
2001 } |
|
2002 |
|
2003 DEFUN (subsref, args, nargout, |
|
2004 "-*- texinfo -*-\n\ |
|
2005 @deftypefn {Built-in Function} {} subsref (@var{val}, @var{idx})\n\ |
|
2006 Perform the subscripted element selection operation according to\n\ |
|
2007 the subscript specified by @var{idx}.\n\ |
|
2008 \n\ |
|
2009 The subscript @var{idx} is expected to be a structure array with\n\ |
|
2010 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ |
6550
|
2011 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153
|
2012 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
|
2013 of index values.\n\ |
6631
|
2014 \n\ |
|
2015 The following example shows how to extract the two first columns of\n\ |
|
2016 a matrix\n\ |
|
2017 \n\ |
|
2018 @example\n\ |
|
2019 val = magic(3)\n\ |
|
2020 @result{} val = [ 8 1 6\n\ |
|
2021 3 5 7\n\ |
|
2022 4 9 2 ]\n\ |
|
2023 idx.type = \"()\";\n\ |
|
2024 idx.subs = @{\":\", 1:2@};\n\ |
|
2025 subsref(val, idx)\n\ |
|
2026 @result{} [ 8 1 \n\ |
|
2027 3 5 \n\ |
|
2028 4 9 ]\n\ |
|
2029 @end example\n\ |
|
2030 \n\ |
|
2031 @noindent\n\ |
|
2032 Note that this is the same as writing @code{val(:,1:2)}.\n\ |
6157
|
2033 @seealso{subsasgn, substruct}\n\ |
6153
|
2034 @end deftypefn") |
|
2035 { |
|
2036 octave_value_list retval; |
|
2037 |
|
2038 if (args.length () == 2) |
|
2039 { |
|
2040 std::string type; |
|
2041 std::list<octave_value_list> idx; |
|
2042 |
|
2043 decode_subscripts ("subsref", args(1), type, idx); |
|
2044 |
|
2045 if (! error_state) |
|
2046 retval = args(0).subsref (type, idx, nargout); |
|
2047 } |
|
2048 else |
|
2049 print_usage (); |
|
2050 |
|
2051 return retval; |
|
2052 } |
|
2053 |
|
2054 DEFUN (subsasgn, args, , |
|
2055 "-*- texinfo -*-\n\ |
|
2056 @deftypefn {Built-in Function} {} subsasgn (@var{val}, @var{idx}, @var{rhs})\n\ |
|
2057 Perform the subscripted assignment operation according to\n\ |
|
2058 the subscript specified by @var{idx}.\n\ |
|
2059 \n\ |
|
2060 The subscript @var{idx} is expected to be a structure array with\n\ |
|
2061 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ |
6248
|
2062 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153
|
2063 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
|
2064 of index values.\n\ |
6631
|
2065 \n\ |
|
2066 The following example shows how to set the two first columns of a\n\ |
|
2067 3-by-3 matrix to zero.\n\ |
|
2068 \n\ |
|
2069 @example\n\ |
|
2070 val = magic(3);\n\ |
|
2071 idx.type = \"()\";\n\ |
|
2072 idx.subs = @{\":\", 1:2@};\n\ |
|
2073 subsasgn (val, idx, 0)\n\ |
|
2074 @result{} [ 0 0 6\n\ |
|
2075 0 0 7\n\ |
|
2076 0 0 2 ]\n\ |
|
2077 @end example\n\ |
|
2078 \n\ |
|
2079 Note that this is the same as writing @code{val(:,1:2) = 0}.\n\ |
6157
|
2080 @seealso{subsref, substruct}\n\ |
6153
|
2081 @end deftypefn") |
|
2082 { |
|
2083 octave_value retval; |
|
2084 |
|
2085 if (args.length () == 3) |
|
2086 { |
|
2087 std::string type; |
|
2088 std::list<octave_value_list> idx; |
|
2089 |
|
2090 decode_subscripts ("subsasgn", args(1), type, idx); |
|
2091 |
|
2092 if (! error_state) |
|
2093 retval = args(0).subsasgn (type, idx, args(2)); |
|
2094 } |
|
2095 else |
|
2096 print_usage (); |
|
2097 |
|
2098 return retval; |
|
2099 } |
|
2100 |
2376
|
2101 /* |
|
2102 ;;; Local Variables: *** |
|
2103 ;;; mode: C++ *** |
|
2104 ;;; End: *** |
|
2105 */ |