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