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