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