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) |
5477
|
419 : rep (is_csl |
|
420 ? dynamic_cast<octave_value *> (new octave_cs_list (c)) |
|
421 : dynamic_cast<octave_value *> (new octave_cell (c))) |
3351
|
422 { |
|
423 rep->count = 1; |
|
424 } |
|
425 |
5147
|
426 octave_value::octave_value (const ArrayN<octave_value>& a, bool is_csl) |
5477
|
427 : rep (is_csl |
|
428 ? dynamic_cast<octave_value *> (new octave_cs_list (Cell (a))) |
|
429 : dynamic_cast<octave_value *> (new octave_cell (Cell (a)))) |
5147
|
430 { |
|
431 rep->count = 1; |
|
432 } |
|
433 |
2376
|
434 octave_value::octave_value (const Matrix& m) |
2423
|
435 : rep (new octave_matrix (m)) |
|
436 { |
|
437 rep->count = 1; |
|
438 maybe_mutate (); |
|
439 } |
2376
|
440 |
4507
|
441 octave_value::octave_value (const NDArray& a) |
4513
|
442 : rep (new octave_matrix (a)) |
4478
|
443 { |
|
444 rep->count = 1; |
|
445 maybe_mutate (); |
|
446 } |
|
447 |
4911
|
448 octave_value::octave_value (const ArrayN<double>& a) |
|
449 : rep (new octave_matrix (a)) |
|
450 { |
|
451 rep->count = 1; |
|
452 maybe_mutate (); |
|
453 } |
|
454 |
2376
|
455 octave_value::octave_value (const DiagMatrix& d) |
2423
|
456 : rep (new octave_matrix (d)) |
|
457 { |
|
458 rep->count = 1; |
|
459 maybe_mutate (); |
|
460 } |
2376
|
461 |
3418
|
462 octave_value::octave_value (const RowVector& v) |
|
463 : rep (new octave_matrix (v)) |
2423
|
464 { |
|
465 rep->count = 1; |
|
466 maybe_mutate (); |
|
467 } |
2376
|
468 |
3418
|
469 octave_value::octave_value (const ColumnVector& v) |
|
470 : rep (new octave_matrix (v)) |
2423
|
471 { |
|
472 rep->count = 1; |
|
473 maybe_mutate (); |
|
474 } |
2376
|
475 |
|
476 octave_value::octave_value (const Complex& C) |
2423
|
477 : rep (new octave_complex (C)) |
|
478 { |
|
479 rep->count = 1; |
|
480 maybe_mutate (); |
|
481 } |
2376
|
482 |
|
483 octave_value::octave_value (const ComplexMatrix& m) |
2423
|
484 : rep (new octave_complex_matrix (m)) |
|
485 { |
|
486 rep->count = 1; |
|
487 maybe_mutate (); |
|
488 } |
2376
|
489 |
4513
|
490 octave_value::octave_value (const ComplexNDArray& a) |
|
491 : rep (new octave_complex_matrix (a)) |
4478
|
492 { |
|
493 rep->count = 1; |
|
494 maybe_mutate (); |
|
495 } |
|
496 |
4911
|
497 octave_value::octave_value (const ArrayN<Complex>& a) |
|
498 : rep (new octave_complex_matrix (a)) |
|
499 { |
|
500 rep->count = 1; |
|
501 maybe_mutate (); |
|
502 } |
|
503 |
2376
|
504 octave_value::octave_value (const ComplexDiagMatrix& d) |
2423
|
505 : rep (new octave_complex_matrix (d)) |
|
506 { |
|
507 rep->count = 1; |
|
508 maybe_mutate (); |
|
509 } |
2376
|
510 |
3418
|
511 octave_value::octave_value (const ComplexRowVector& v) |
|
512 : rep (new octave_complex_matrix (v)) |
2423
|
513 { |
|
514 rep->count = 1; |
|
515 maybe_mutate (); |
|
516 } |
2376
|
517 |
3418
|
518 octave_value::octave_value (const ComplexColumnVector& v) |
|
519 : rep (new octave_complex_matrix (v)) |
2423
|
520 { |
|
521 rep->count = 1; |
|
522 maybe_mutate (); |
|
523 } |
2376
|
524 |
2825
|
525 octave_value::octave_value (bool b) |
|
526 : rep (new octave_bool (b)) |
|
527 { |
|
528 rep->count = 1; |
|
529 } |
|
530 |
|
531 octave_value::octave_value (const boolMatrix& bm) |
|
532 : rep (new octave_bool_matrix (bm)) |
|
533 { |
|
534 rep->count = 1; |
|
535 maybe_mutate (); |
|
536 } |
|
537 |
4513
|
538 octave_value::octave_value (const boolNDArray& bnda) |
|
539 : rep (new octave_bool_matrix (bnda)) |
|
540 { |
|
541 rep->count = 1; |
|
542 maybe_mutate (); |
|
543 } |
|
544 |
5279
|
545 octave_value::octave_value (char c, char type) |
|
546 : rep (type == '"' |
|
547 ? new octave_char_matrix_dq_str (c) |
|
548 : new octave_char_matrix_sq_str (c)) |
3189
|
549 { |
|
550 rep->count = 1; |
|
551 maybe_mutate (); |
|
552 } |
|
553 |
5279
|
554 octave_value::octave_value (const char *s, char type) |
|
555 : rep (type == '"' |
|
556 ? new octave_char_matrix_dq_str (s) |
|
557 : new octave_char_matrix_sq_str (s)) |
2423
|
558 { |
|
559 rep->count = 1; |
|
560 maybe_mutate (); |
|
561 } |
2376
|
562 |
5279
|
563 octave_value::octave_value (const std::string& s, char type) |
|
564 : rep (type == '"' |
|
565 ? new octave_char_matrix_dq_str (s) |
|
566 : new octave_char_matrix_sq_str (s)) |
2423
|
567 { |
|
568 rep->count = 1; |
|
569 maybe_mutate (); |
|
570 } |
2376
|
571 |
5279
|
572 octave_value::octave_value (const string_vector& s, char type) |
|
573 : rep (type == '"' |
|
574 ? new octave_char_matrix_dq_str (s) |
|
575 : new octave_char_matrix_sq_str (s)) |
2423
|
576 { |
|
577 rep->count = 1; |
|
578 maybe_mutate (); |
|
579 } |
2376
|
580 |
5279
|
581 octave_value::octave_value (const charMatrix& chm, bool is_str, char type) |
4587
|
582 : rep (is_str |
5279
|
583 ? (type == '"' |
|
584 ? new octave_char_matrix_dq_str (chm) |
|
585 : new octave_char_matrix_sq_str (chm)) |
4513
|
586 : new octave_char_matrix (chm)) |
2409
|
587 { |
4513
|
588 rep->count = 1; |
|
589 maybe_mutate (); |
|
590 } |
2376
|
591 |
5279
|
592 octave_value::octave_value (const charNDArray& chm, bool is_str, char type) |
4587
|
593 : rep (is_str |
5279
|
594 ? (type == '"' |
|
595 ? new octave_char_matrix_dq_str (chm) |
|
596 : new octave_char_matrix_sq_str (chm)) |
4513
|
597 : new octave_char_matrix (chm)) |
|
598 { |
2409
|
599 rep->count = 1; |
2423
|
600 maybe_mutate (); |
2409
|
601 } |
2376
|
602 |
5279
|
603 octave_value::octave_value (const ArrayN<char>& chm, bool is_str, char type) |
4997
|
604 : rep (is_str |
5279
|
605 ? (type == '"' |
|
606 ? new octave_char_matrix_dq_str (chm) |
|
607 : new octave_char_matrix_sq_str (chm)) |
4997
|
608 : new octave_char_matrix (chm)) |
|
609 { |
|
610 rep->count = 1; |
|
611 maybe_mutate (); |
|
612 } |
|
613 |
5164
|
614 octave_value::octave_value (const SparseMatrix& m, const SparseType &t) |
|
615 : rep (new octave_sparse_matrix (m, t)) |
|
616 { |
|
617 rep->count = 1; |
|
618 maybe_mutate (); |
|
619 } |
|
620 |
|
621 octave_value::octave_value (const SparseComplexMatrix& m, const SparseType &t) |
|
622 : rep (new octave_sparse_complex_matrix (m, t)) |
|
623 { |
|
624 rep->count = 1; |
|
625 maybe_mutate (); |
|
626 } |
|
627 |
|
628 octave_value::octave_value (const SparseBoolMatrix& bm, const SparseType &t) |
|
629 : rep (new octave_sparse_bool_matrix (bm, t)) |
|
630 { |
|
631 rep->count = 1; |
|
632 maybe_mutate (); |
|
633 } |
|
634 |
4901
|
635 octave_value::octave_value (const octave_int8& i) |
|
636 : rep (new octave_int8_scalar (i)) |
|
637 { |
|
638 rep->count = 1; |
|
639 maybe_mutate (); |
|
640 } |
|
641 |
|
642 octave_value::octave_value (const octave_uint8& i) |
|
643 : rep (new octave_uint8_scalar (i)) |
|
644 { |
|
645 rep->count = 1; |
|
646 maybe_mutate (); |
|
647 } |
|
648 |
|
649 octave_value::octave_value (const octave_int16& i) |
|
650 : rep (new octave_int16_scalar (i)) |
|
651 { |
|
652 rep->count = 1; |
|
653 maybe_mutate (); |
|
654 } |
|
655 |
|
656 octave_value::octave_value (const octave_uint16& i) |
|
657 : rep (new octave_uint16_scalar (i)) |
|
658 { |
|
659 rep->count = 1; |
|
660 maybe_mutate (); |
|
661 } |
|
662 |
|
663 octave_value::octave_value (const octave_int32& i) |
|
664 : rep (new octave_int32_scalar (i)) |
|
665 { |
|
666 rep->count = 1; |
|
667 maybe_mutate (); |
|
668 } |
|
669 |
|
670 octave_value::octave_value (const octave_uint32& i) |
|
671 : rep (new octave_uint32_scalar (i)) |
|
672 { |
|
673 rep->count = 1; |
|
674 maybe_mutate (); |
|
675 } |
|
676 |
|
677 octave_value::octave_value (const octave_int64& i) |
|
678 : rep (new octave_int64_scalar (i)) |
|
679 { |
|
680 rep->count = 1; |
|
681 maybe_mutate (); |
|
682 } |
|
683 |
|
684 octave_value::octave_value (const octave_uint64& i) |
|
685 : rep (new octave_uint64_scalar (i)) |
|
686 { |
|
687 rep->count = 1; |
|
688 maybe_mutate (); |
|
689 } |
|
690 |
|
691 octave_value::octave_value (const int8NDArray& inda) |
|
692 : rep (new octave_int8_matrix (inda)) |
|
693 { |
|
694 rep->count = 1; |
|
695 maybe_mutate (); |
|
696 } |
|
697 |
|
698 octave_value::octave_value (const uint8NDArray& inda) |
|
699 : rep (new octave_uint8_matrix (inda)) |
|
700 { |
|
701 rep->count = 1; |
|
702 maybe_mutate (); |
|
703 } |
|
704 |
|
705 octave_value::octave_value (const int16NDArray& inda) |
|
706 : rep (new octave_int16_matrix (inda)) |
|
707 { |
|
708 rep->count = 1; |
|
709 maybe_mutate (); |
|
710 } |
|
711 |
|
712 octave_value::octave_value (const uint16NDArray& inda) |
|
713 : rep (new octave_uint16_matrix (inda)) |
|
714 { |
|
715 rep->count = 1; |
|
716 maybe_mutate (); |
|
717 } |
|
718 |
|
719 octave_value::octave_value (const int32NDArray& inda) |
|
720 : rep (new octave_int32_matrix (inda)) |
|
721 { |
|
722 rep->count = 1; |
|
723 maybe_mutate (); |
|
724 } |
|
725 |
|
726 octave_value::octave_value (const uint32NDArray& inda) |
|
727 : rep (new octave_uint32_matrix (inda)) |
|
728 { |
|
729 rep->count = 1; |
|
730 maybe_mutate (); |
|
731 } |
|
732 |
|
733 octave_value::octave_value (const int64NDArray& inda) |
|
734 : rep (new octave_int64_matrix (inda)) |
|
735 { |
|
736 rep->count = 1; |
|
737 maybe_mutate (); |
|
738 } |
|
739 |
|
740 octave_value::octave_value (const uint64NDArray& inda) |
|
741 : rep (new octave_uint64_matrix (inda)) |
|
742 { |
|
743 rep->count = 1; |
|
744 maybe_mutate (); |
|
745 } |
|
746 |
2376
|
747 octave_value::octave_value (double base, double limit, double inc) |
2423
|
748 : rep (new octave_range (base, limit, inc)) |
|
749 { |
|
750 rep->count = 1; |
|
751 maybe_mutate (); |
|
752 } |
2376
|
753 |
|
754 octave_value::octave_value (const Range& r) |
2423
|
755 : rep (new octave_range (r)) |
|
756 { |
|
757 rep->count = 1; |
|
758 maybe_mutate (); |
|
759 } |
2376
|
760 |
|
761 octave_value::octave_value (const Octave_map& m) |
2825
|
762 : rep (new octave_struct (m)) |
|
763 { |
|
764 rep->count = 1; |
2880
|
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) |
5477
|
774 : rep (is_csl |
|
775 ? dynamic_cast<octave_value *> (new octave_cs_list (l)) |
|
776 : dynamic_cast<octave_value *> (new octave_list (l))) |
2880
|
777 { |
|
778 rep->count = 1; |
|
779 } |
2376
|
780 |
|
781 octave_value::octave_value (octave_value::magic_colon) |
2825
|
782 : rep (new octave_magic_colon ()) |
|
783 { |
|
784 rep->count = 1; |
|
785 } |
2376
|
786 |
|
787 octave_value::octave_value (octave_value::all_va_args) |
2825
|
788 : rep (new octave_all_va_args ()) |
|
789 { |
|
790 rep->count = 1; |
|
791 } |
2376
|
792 |
4276
|
793 octave_value::octave_value (octave_value *new_rep, int cnt) |
2825
|
794 : rep (new_rep) |
|
795 { |
4276
|
796 rep->count = cnt; |
2825
|
797 } |
2376
|
798 |
|
799 octave_value::~octave_value (void) |
|
800 { |
|
801 #if defined (MDEBUG) |
5539
|
802 if (rep) |
|
803 std::cerr << "~octave_value: rep: " << rep |
|
804 << " rep->count: " << rep->count << std::endl; |
|
805 else |
|
806 std::cerr << "~octave_value: rep is 0!" << std::endl; |
2376
|
807 #endif |
|
808 |
|
809 if (rep && --rep->count == 0) |
5539
|
810 { |
|
811 delete rep; |
|
812 rep = 0; |
|
813 } |
2376
|
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 |
4645
|
1096 std::streamoff |
4643
|
1097 octave_value::streamoff_value (void) const |
|
1098 { |
|
1099 return rep->streamoff_value (); |
|
1100 } |
|
1101 |
4645
|
1102 streamoff_array |
|
1103 octave_value::streamoff_array_value (void) const |
|
1104 { |
|
1105 return rep->streamoff_array_value (); |
|
1106 } |
|
1107 |
2974
|
1108 octave_function * |
|
1109 octave_value::function_value (bool silent) |
|
1110 { |
|
1111 return rep->function_value (silent); |
|
1112 } |
|
1113 |
4700
|
1114 octave_user_function * |
|
1115 octave_value::user_function_value (bool silent) |
|
1116 { |
|
1117 return rep->user_function_value (silent); |
|
1118 } |
|
1119 |
4346
|
1120 octave_fcn_handle * |
4343
|
1121 octave_value::fcn_handle_value (bool silent) |
|
1122 { |
|
1123 return rep->fcn_handle_value (silent); |
|
1124 } |
|
1125 |
4933
|
1126 octave_fcn_inline * |
|
1127 octave_value::fcn_inline_value (bool silent) |
|
1128 { |
|
1129 return rep->fcn_inline_value (silent); |
|
1130 } |
|
1131 |
2880
|
1132 octave_value_list |
|
1133 octave_value::list_value (void) const |
|
1134 { |
|
1135 return rep->list_value (); |
|
1136 } |
|
1137 |
2376
|
1138 ColumnVector |
3419
|
1139 octave_value::column_vector_value (bool force_string_conv, |
4661
|
1140 bool /* frc_vec_conv */) const |
3419
|
1141 { |
|
1142 ColumnVector retval; |
|
1143 |
|
1144 Matrix m = matrix_value (force_string_conv); |
|
1145 |
|
1146 if (error_state) |
|
1147 return retval; |
|
1148 |
5275
|
1149 octave_idx_type nr = m.rows (); |
|
1150 octave_idx_type nc = m.columns (); |
3419
|
1151 |
|
1152 if (nc == 1) |
|
1153 { |
|
1154 retval.resize (nr); |
5275
|
1155 for (octave_idx_type i = 0; i < nr; i++) |
3419
|
1156 retval (i) = m (i, 0); |
|
1157 } |
|
1158 else |
|
1159 { |
3523
|
1160 std::string tn = type_name (); |
3419
|
1161 gripe_invalid_conversion (tn.c_str (), "real column vector"); |
|
1162 } |
|
1163 |
|
1164 return retval; |
|
1165 } |
|
1166 |
|
1167 ComplexColumnVector |
|
1168 octave_value::complex_column_vector_value (bool force_string_conv, |
4661
|
1169 bool /* frc_vec_conv */) const |
3419
|
1170 { |
|
1171 ComplexColumnVector retval; |
|
1172 |
|
1173 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1174 |
|
1175 if (error_state) |
|
1176 return retval; |
|
1177 |
5275
|
1178 octave_idx_type nr = m.rows (); |
|
1179 octave_idx_type nc = m.columns (); |
3419
|
1180 |
|
1181 if (nc == 1) |
|
1182 { |
3465
|
1183 retval.resize (nr); |
5275
|
1184 for (octave_idx_type i = 0; i < nr; i++) |
3419
|
1185 retval (i) = m (i, 0); |
|
1186 } |
|
1187 else |
|
1188 { |
3523
|
1189 std::string tn = type_name (); |
3419
|
1190 gripe_invalid_conversion (tn.c_str (), "complex column vector"); |
|
1191 } |
|
1192 |
|
1193 return retval; |
|
1194 } |
|
1195 |
|
1196 RowVector |
|
1197 octave_value::row_vector_value (bool force_string_conv, |
4661
|
1198 bool /* frc_vec_conv */) const |
3419
|
1199 { |
|
1200 RowVector retval; |
|
1201 |
|
1202 Matrix m = matrix_value (force_string_conv); |
|
1203 |
|
1204 if (error_state) |
|
1205 return retval; |
|
1206 |
5275
|
1207 octave_idx_type nr = m.rows (); |
|
1208 octave_idx_type nc = m.columns (); |
3419
|
1209 |
|
1210 if (nr == 1) |
|
1211 { |
|
1212 retval.resize (nc); |
5275
|
1213 for (octave_idx_type i = 0; i < nc; i++) |
3419
|
1214 retval (i) = m (0, i); |
|
1215 } |
|
1216 else |
|
1217 { |
3523
|
1218 std::string tn = type_name (); |
3419
|
1219 gripe_invalid_conversion (tn.c_str (), "real row vector"); |
|
1220 } |
|
1221 |
|
1222 return retval; |
|
1223 } |
|
1224 |
|
1225 ComplexRowVector |
|
1226 octave_value::complex_row_vector_value (bool force_string_conv, |
4661
|
1227 bool /* frc_vec_conv */) const |
3419
|
1228 { |
|
1229 ComplexRowVector retval; |
|
1230 |
|
1231 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1232 |
|
1233 if (error_state) |
|
1234 return retval; |
|
1235 |
5275
|
1236 octave_idx_type nr = m.rows (); |
|
1237 octave_idx_type nc = m.columns (); |
3419
|
1238 |
|
1239 if (nr == 1) |
|
1240 { |
|
1241 retval.resize (nc); |
5275
|
1242 for (octave_idx_type i = 0; i < nc; i++) |
3419
|
1243 retval (i) = m (0, i); |
|
1244 } |
|
1245 else |
|
1246 { |
3523
|
1247 std::string tn = type_name (); |
3419
|
1248 gripe_invalid_conversion (tn.c_str (), "complex row vector"); |
|
1249 } |
|
1250 |
|
1251 return retval; |
|
1252 } |
|
1253 |
|
1254 // Sloppy... |
|
1255 |
|
1256 Array<double> |
2376
|
1257 octave_value::vector_value (bool force_string_conv, |
|
1258 bool force_vector_conversion) const |
|
1259 { |
3419
|
1260 Array<double> retval; |
2376
|
1261 |
|
1262 Matrix m = matrix_value (force_string_conv); |
|
1263 |
|
1264 if (error_state) |
|
1265 return retval; |
|
1266 |
5275
|
1267 octave_idx_type nr = m.rows (); |
|
1268 octave_idx_type nc = m.columns (); |
2376
|
1269 |
|
1270 if (nr == 1) |
|
1271 { |
|
1272 retval.resize (nc); |
5275
|
1273 for (octave_idx_type i = 0; i < nc; i++) |
2376
|
1274 retval (i) = m (0, i); |
|
1275 } |
|
1276 else if (nc == 1) |
|
1277 { |
|
1278 retval.resize (nr); |
5275
|
1279 for (octave_idx_type i = 0; i < nr; i++) |
2376
|
1280 retval (i) = m (i, 0); |
|
1281 } |
4455
|
1282 else if (nr > 0 && nc > 0) |
2376
|
1283 { |
4455
|
1284 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
1285 if (! force_vector_conversion && Vwarn_fortran_indexing) |
|
1286 gripe_implicit_conversion (type_name (), "real vector"); |
|
1287 |
2376
|
1288 retval.resize (nr * nc); |
5275
|
1289 octave_idx_type k = 0; |
|
1290 for (octave_idx_type j = 0; j < nc; j++) |
|
1291 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
1292 { |
|
1293 OCTAVE_QUIT; |
|
1294 |
|
1295 retval (k++) = m (i, j); |
|
1296 } |
2376
|
1297 } |
|
1298 else |
|
1299 { |
3523
|
1300 std::string tn = type_name (); |
2376
|
1301 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
1302 } |
|
1303 |
|
1304 return retval; |
|
1305 } |
|
1306 |
4044
|
1307 Array<int> |
|
1308 octave_value::int_vector_value (bool force_string_conv, bool require_int, |
|
1309 bool force_vector_conversion) const |
|
1310 { |
|
1311 Array<int> retval; |
|
1312 |
|
1313 Matrix m = matrix_value (force_string_conv); |
|
1314 |
|
1315 if (error_state) |
|
1316 return retval; |
|
1317 |
5275
|
1318 octave_idx_type nr = m.rows (); |
|
1319 octave_idx_type nc = m.columns (); |
4044
|
1320 |
|
1321 if (nr == 1) |
|
1322 { |
|
1323 retval.resize (nc); |
5275
|
1324 for (octave_idx_type i = 0; i < nc; i++) |
4044
|
1325 { |
4153
|
1326 OCTAVE_QUIT; |
|
1327 |
4044
|
1328 double d = m (0, i); |
|
1329 |
|
1330 if (require_int && D_NINT (d) != d) |
|
1331 { |
|
1332 error ("conversion to integer value failed"); |
|
1333 return retval; |
|
1334 } |
|
1335 |
|
1336 retval (i) = static_cast<int> (d); |
|
1337 } |
|
1338 } |
|
1339 else if (nc == 1) |
|
1340 { |
|
1341 retval.resize (nr); |
5275
|
1342 for (octave_idx_type i = 0; i < nr; i++) |
4044
|
1343 { |
4153
|
1344 OCTAVE_QUIT; |
|
1345 |
4044
|
1346 double d = m (i, 0); |
|
1347 |
|
1348 if (require_int && D_NINT (d) != d) |
|
1349 { |
|
1350 error ("conversion to integer value failed"); |
|
1351 return retval; |
|
1352 } |
|
1353 |
|
1354 retval (i) = static_cast<int> (d); |
|
1355 } |
|
1356 } |
4455
|
1357 else if (nr > 0 && nc > 0) |
4044
|
1358 { |
4455
|
1359 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
1360 if (! force_vector_conversion && Vwarn_fortran_indexing) |
|
1361 gripe_implicit_conversion (type_name (), "real vector"); |
|
1362 |
4044
|
1363 retval.resize (nr * nc); |
5275
|
1364 octave_idx_type k = 0; |
|
1365 for (octave_idx_type j = 0; j < nc; j++) |
4044
|
1366 { |
5275
|
1367 for (octave_idx_type i = 0; i < nr; i++) |
4044
|
1368 { |
4153
|
1369 OCTAVE_QUIT; |
|
1370 |
4044
|
1371 double d = m (i, j); |
|
1372 |
|
1373 if (require_int && D_NINT (d) != d) |
|
1374 { |
|
1375 error ("conversion to integer value failed"); |
|
1376 return retval; |
|
1377 } |
|
1378 |
|
1379 retval (k++) = static_cast<int> (d); |
|
1380 } |
|
1381 } |
|
1382 } |
|
1383 else |
|
1384 { |
|
1385 std::string tn = type_name (); |
|
1386 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
1387 } |
|
1388 |
|
1389 return retval; |
|
1390 } |
|
1391 |
3419
|
1392 Array<Complex> |
2376
|
1393 octave_value::complex_vector_value (bool force_string_conv, |
|
1394 bool force_vector_conversion) const |
|
1395 { |
3419
|
1396 Array<Complex> retval; |
2376
|
1397 |
|
1398 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1399 |
|
1400 if (error_state) |
|
1401 return retval; |
|
1402 |
5275
|
1403 octave_idx_type nr = m.rows (); |
|
1404 octave_idx_type nc = m.columns (); |
2376
|
1405 |
|
1406 if (nr == 1) |
|
1407 { |
|
1408 retval.resize (nc); |
5275
|
1409 for (octave_idx_type i = 0; i < nc; i++) |
4153
|
1410 { |
|
1411 OCTAVE_QUIT; |
|
1412 retval (i) = m (0, i); |
|
1413 } |
2376
|
1414 } |
|
1415 else if (nc == 1) |
|
1416 { |
|
1417 retval.resize (nr); |
5275
|
1418 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
1419 { |
|
1420 OCTAVE_QUIT; |
|
1421 retval (i) = m (i, 0); |
|
1422 } |
2376
|
1423 } |
4455
|
1424 else if (nr > 0 && nc > 0) |
2376
|
1425 { |
4455
|
1426 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
1427 if (! force_vector_conversion && Vwarn_fortran_indexing) |
|
1428 gripe_implicit_conversion (type_name (), "complex vector"); |
|
1429 |
2376
|
1430 retval.resize (nr * nc); |
5275
|
1431 octave_idx_type k = 0; |
|
1432 for (octave_idx_type j = 0; j < nc; j++) |
|
1433 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
1434 { |
|
1435 OCTAVE_QUIT; |
|
1436 retval (k++) = m (i, j); |
|
1437 } |
2376
|
1438 } |
|
1439 else |
|
1440 { |
3523
|
1441 std::string tn = type_name (); |
2376
|
1442 gripe_invalid_conversion (tn.c_str (), "complex vector"); |
|
1443 } |
|
1444 |
|
1445 return retval; |
|
1446 } |
|
1447 |
4452
|
1448 octave_value |
5279
|
1449 octave_value::convert_to_str (bool pad, bool force, char type) const |
4452
|
1450 { |
5279
|
1451 octave_value retval = convert_to_str_internal (pad, force, type); |
4452
|
1452 |
4457
|
1453 if (! force && is_numeric_type () && Vwarn_num_to_str) |
4452
|
1454 gripe_implicit_conversion (type_name (), retval.type_name ()); |
|
1455 |
|
1456 return retval; |
|
1457 } |
|
1458 |
2376
|
1459 void |
4005
|
1460 octave_value::print_with_name (std::ostream& output_buf, |
|
1461 const std::string& name, |
2903
|
1462 bool print_padding) const |
2376
|
1463 { |
4005
|
1464 if (! (evaluating_function_body && Vsilent_functions)) |
|
1465 { |
4894
|
1466 bool pad_after = false; |
|
1467 |
|
1468 if (Vprint_answer_id_name) |
|
1469 pad_after = print_name_tag (output_buf, name); |
2376
|
1470 |
4005
|
1471 print (output_buf); |
2376
|
1472 |
4005
|
1473 if (print_padding && pad_after) |
|
1474 newline (output_buf); |
|
1475 } |
2376
|
1476 } |
|
1477 |
|
1478 static void |
3523
|
1479 gripe_indexed_assignment (const std::string& tn1, const std::string& tn2) |
2413
|
1480 { |
2903
|
1481 error ("assignment of `%s' to indexed `%s' not implemented", |
2413
|
1482 tn2.c_str (), tn1.c_str ()); |
|
1483 } |
|
1484 |
|
1485 static void |
3933
|
1486 gripe_assign_conversion_failed (const std::string& tn1, |
|
1487 const std::string& tn2) |
2413
|
1488 { |
2903
|
1489 error ("type conversion for assignment of `%s' to indexed `%s' failed", |
2413
|
1490 tn2.c_str (), tn1.c_str ()); |
|
1491 } |
|
1492 |
4944
|
1493 int |
|
1494 octave_value::write (octave_stream& os, int block_size, |
|
1495 oct_data_conv::data_type output_type, int skip, |
|
1496 oct_mach_info::float_format flt_fmt) const |
|
1497 { |
|
1498 return rep->write (os, block_size, output_type, skip, flt_fmt); |
|
1499 } |
|
1500 |
3933
|
1501 octave_value |
4247
|
1502 octave_value::numeric_assign (const std::string& type, |
4219
|
1503 const std::list<octave_value_list>& idx, |
2413
|
1504 const octave_value& rhs) |
|
1505 { |
3933
|
1506 octave_value retval; |
2413
|
1507 |
|
1508 int t_lhs = type_id (); |
|
1509 int t_rhs = rhs.type_id (); |
|
1510 |
2880
|
1511 assign_op_fcn f |
3933
|
1512 = octave_value_typeinfo::lookup_assign_op (op_asn_eq, t_lhs, t_rhs); |
|
1513 |
|
1514 bool done = false; |
2413
|
1515 |
|
1516 if (f) |
|
1517 { |
3933
|
1518 f (*this, idx.front (), rhs.get_rep ()); |
2413
|
1519 |
3933
|
1520 done = (! error_state); |
2413
|
1521 } |
3933
|
1522 |
|
1523 if (done) |
|
1524 retval = octave_value (this, count + 1); |
3196
|
1525 else |
|
1526 { |
3933
|
1527 int t_result |
|
1528 = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); |
|
1529 |
|
1530 if (t_result >= 0) |
|
1531 { |
|
1532 type_conv_fcn cf |
|
1533 = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); |
|
1534 |
|
1535 if (cf) |
|
1536 { |
|
1537 octave_value *tmp (cf (*this)); |
3196
|
1538 |
3933
|
1539 if (tmp) |
|
1540 { |
|
1541 retval = tmp->subsasgn (type, idx, rhs); |
|
1542 |
|
1543 done = (! error_state); |
|
1544 } |
|
1545 else |
|
1546 gripe_assign_conversion_failed (type_name (), |
|
1547 rhs.type_name ()); |
|
1548 } |
|
1549 else |
|
1550 gripe_indexed_assignment (type_name (), rhs.type_name ()); |
|
1551 } |
|
1552 |
|
1553 if (! (done || error_state)) |
3196
|
1554 { |
3933
|
1555 octave_value tmp_rhs; |
|
1556 type_conv_fcn cf_rhs = rhs.numeric_conversion_function (); |
|
1557 |
|
1558 if (cf_rhs) |
|
1559 { |
|
1560 octave_value *tmp = cf_rhs (rhs.get_rep ()); |
|
1561 |
|
1562 if (tmp) |
|
1563 tmp_rhs = octave_value (tmp); |
|
1564 else |
|
1565 { |
|
1566 gripe_assign_conversion_failed (type_name (), |
|
1567 rhs.type_name ()); |
|
1568 return octave_value (); |
|
1569 } |
|
1570 } |
|
1571 else |
|
1572 tmp_rhs = rhs; |
|
1573 |
|
1574 type_conv_fcn cf_this = numeric_conversion_function (); |
|
1575 |
|
1576 octave_value *tmp_lhs = this; |
3196
|
1577 |
3933
|
1578 if (cf_this) |
|
1579 { |
|
1580 octave_value *tmp = cf_this (*this); |
|
1581 |
|
1582 if (tmp) |
|
1583 tmp_lhs = tmp; |
|
1584 else |
|
1585 { |
|
1586 gripe_assign_conversion_failed (type_name (), |
|
1587 rhs.type_name ()); |
|
1588 return octave_value (); |
|
1589 } |
|
1590 } |
|
1591 |
|
1592 if (cf_this || cf_rhs) |
|
1593 { |
|
1594 retval = tmp_lhs->subsasgn (type, idx, tmp_rhs); |
|
1595 |
|
1596 done = (! error_state); |
|
1597 } |
|
1598 else |
|
1599 gripe_no_conversion (assign_op_as_string (op_asn_eq), |
|
1600 type_name (), rhs.type_name ()); |
3196
|
1601 } |
|
1602 } |
2413
|
1603 |
4858
|
1604 // The assignment may have converted to a type that is wider than |
|
1605 // necessary. |
|
1606 |
|
1607 retval.maybe_mutate (); |
|
1608 |
2413
|
1609 return retval; |
|
1610 } |
|
1611 |
|
1612 static void |
3933
|
1613 gripe_binary_op (const std::string& on, const std::string& tn1, |
|
1614 const std::string& tn2) |
2376
|
1615 { |
2903
|
1616 error ("binary operator `%s' not implemented for `%s' by `%s' operations", |
2376
|
1617 on.c_str (), tn1.c_str (), tn2.c_str ()); |
|
1618 } |
|
1619 |
3203
|
1620 static void |
3523
|
1621 gripe_binary_op_conv (const std::string& on) |
3203
|
1622 { |
|
1623 error ("type conversion failed for binary operator `%s'", on.c_str ()); |
|
1624 } |
|
1625 |
2376
|
1626 octave_value |
3933
|
1627 do_binary_op (octave_value::binary_op op, |
|
1628 const octave_value& v1, const octave_value& v2) |
2376
|
1629 { |
|
1630 octave_value retval; |
|
1631 |
|
1632 int t1 = v1.type_id (); |
|
1633 int t2 = v2.type_id (); |
|
1634 |
2427
|
1635 binary_op_fcn f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1636 |
|
1637 if (f) |
|
1638 retval = f (*v1.rep, *v2.rep); |
|
1639 else |
|
1640 { |
|
1641 octave_value tv1; |
2427
|
1642 type_conv_fcn cf1 = v1.numeric_conversion_function (); |
2376
|
1643 |
|
1644 if (cf1) |
|
1645 { |
3203
|
1646 octave_value *tmp = cf1 (*v1.rep); |
|
1647 |
|
1648 if (tmp) |
|
1649 { |
|
1650 tv1 = octave_value (tmp); |
|
1651 t1 = tv1.type_id (); |
|
1652 } |
|
1653 else |
|
1654 { |
|
1655 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1656 return retval; |
|
1657 } |
2376
|
1658 } |
|
1659 else |
|
1660 tv1 = v1; |
|
1661 |
|
1662 octave_value tv2; |
2427
|
1663 type_conv_fcn cf2 = v2.numeric_conversion_function (); |
2376
|
1664 |
|
1665 if (cf2) |
|
1666 { |
3203
|
1667 octave_value *tmp = cf2 (*v2.rep); |
|
1668 |
|
1669 if (tmp) |
|
1670 { |
|
1671 tv2 = octave_value (tmp); |
|
1672 t2 = tv2.type_id (); |
|
1673 } |
|
1674 else |
|
1675 { |
|
1676 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1677 return retval; |
|
1678 } |
2376
|
1679 } |
|
1680 else |
|
1681 tv2 = v2; |
|
1682 |
|
1683 if (cf1 || cf2) |
|
1684 { |
4587
|
1685 f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1686 |
|
1687 if (f) |
|
1688 retval = f (*tv1.rep, *tv2.rep); |
|
1689 else |
|
1690 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1691 v1.type_name (), v2.type_name ()); |
|
1692 } |
|
1693 else |
|
1694 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1695 v1.type_name (), v2.type_name ()); |
|
1696 } |
|
1697 |
|
1698 return retval; |
|
1699 } |
|
1700 |
4915
|
1701 static void |
|
1702 gripe_cat_op (const std::string& tn1, const std::string& tn2) |
|
1703 { |
|
1704 error ("concatenation operator not implemented for `%s' by `%s' operations", |
|
1705 tn1.c_str (), tn2.c_str ()); |
|
1706 } |
|
1707 |
|
1708 static void |
|
1709 gripe_cat_op_conv (void) |
|
1710 { |
|
1711 error ("type conversion failed for concatenation operator"); |
|
1712 } |
|
1713 |
|
1714 octave_value |
|
1715 do_cat_op (const octave_value& v1, const octave_value& v2, |
|
1716 const Array<int>& ra_idx) |
|
1717 { |
|
1718 octave_value retval; |
|
1719 |
5164
|
1720 // Rapid return for concatenation with an empty object. Dimension |
|
1721 // checking handled elsewhere. |
|
1722 if (v1.all_zero_dims ()) |
|
1723 return v2; |
|
1724 if (v2.all_zero_dims ()) |
|
1725 return v1; |
|
1726 |
4915
|
1727 int t1 = v1.type_id (); |
|
1728 int t2 = v2.type_id (); |
|
1729 |
|
1730 cat_op_fcn f = octave_value_typeinfo::lookup_cat_op (t1, t2); |
|
1731 |
|
1732 if (f) |
|
1733 retval = f (*v1.rep, *v2.rep, ra_idx); |
|
1734 else |
|
1735 { |
|
1736 octave_value tv1; |
|
1737 type_conv_fcn cf1 = v1.numeric_conversion_function (); |
|
1738 |
|
1739 if (cf1) |
|
1740 { |
|
1741 octave_value *tmp = cf1 (*v1.rep); |
|
1742 |
|
1743 if (tmp) |
|
1744 { |
|
1745 tv1 = octave_value (tmp); |
|
1746 t1 = tv1.type_id (); |
|
1747 } |
|
1748 else |
|
1749 { |
|
1750 gripe_cat_op_conv (); |
|
1751 return retval; |
|
1752 } |
|
1753 } |
|
1754 else |
|
1755 tv1 = v1; |
|
1756 |
|
1757 octave_value tv2; |
|
1758 type_conv_fcn cf2 = v2.numeric_conversion_function (); |
|
1759 |
|
1760 if (cf2) |
|
1761 { |
|
1762 octave_value *tmp = cf2 (*v2.rep); |
|
1763 |
|
1764 if (tmp) |
|
1765 { |
|
1766 tv2 = octave_value (tmp); |
|
1767 t2 = tv2.type_id (); |
|
1768 } |
|
1769 else |
|
1770 { |
|
1771 gripe_cat_op_conv (); |
|
1772 return retval; |
|
1773 } |
|
1774 } |
|
1775 else |
|
1776 tv2 = v2; |
|
1777 |
|
1778 if (cf1 || cf2) |
|
1779 { |
|
1780 f = octave_value_typeinfo::lookup_cat_op (t1, t2); |
|
1781 |
|
1782 if (f) |
|
1783 retval = f (*tv1.rep, *tv2.rep, ra_idx); |
|
1784 else |
|
1785 gripe_cat_op (v1.type_name (), v2.type_name ()); |
|
1786 } |
|
1787 else |
|
1788 gripe_cat_op (v1.type_name (), v2.type_name ()); |
|
1789 } |
|
1790 |
|
1791 return retval; |
|
1792 } |
|
1793 |
3933
|
1794 void |
|
1795 octave_value::print_info (std::ostream& os, const std::string& prefix) const |
|
1796 { |
|
1797 os << prefix << "type_name: " << type_name () << "\n" |
|
1798 << prefix << "count: " << get_count () << "\n" |
|
1799 << prefix << "rep info: "; |
|
1800 |
|
1801 rep->print_info (os, prefix + " "); |
|
1802 } |
|
1803 |
3203
|
1804 static void |
3523
|
1805 gripe_unary_op (const std::string& on, const std::string& tn) |
3203
|
1806 { |
|
1807 error ("unary operator `%s' not implemented for `%s' operands", |
|
1808 on.c_str (), tn.c_str ()); |
|
1809 } |
|
1810 |
|
1811 static void |
3523
|
1812 gripe_unary_op_conv (const std::string& on) |
3203
|
1813 { |
|
1814 error ("type conversion failed for unary operator `%s'", on.c_str ()); |
|
1815 } |
|
1816 |
|
1817 octave_value |
|
1818 do_unary_op (octave_value::unary_op op, const octave_value& v) |
|
1819 { |
|
1820 octave_value retval; |
|
1821 |
|
1822 int t = v.type_id (); |
|
1823 |
|
1824 unary_op_fcn f = octave_value_typeinfo::lookup_unary_op (op, t); |
|
1825 |
|
1826 if (f) |
|
1827 retval = f (*v.rep); |
|
1828 else |
|
1829 { |
|
1830 octave_value tv; |
|
1831 type_conv_fcn cf = v.numeric_conversion_function (); |
|
1832 |
|
1833 if (cf) |
|
1834 { |
|
1835 octave_value *tmp = cf (*v.rep); |
|
1836 |
|
1837 if (tmp) |
|
1838 { |
|
1839 tv = octave_value (tmp); |
|
1840 t = tv.type_id (); |
|
1841 |
4587
|
1842 f = octave_value_typeinfo::lookup_unary_op (op, t); |
3203
|
1843 |
|
1844 if (f) |
|
1845 retval = f (*tv.rep); |
|
1846 else |
|
1847 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1848 v.type_name ()); |
|
1849 } |
|
1850 else |
|
1851 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
|
1852 } |
|
1853 else |
|
1854 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1855 v.type_name ()); |
|
1856 } |
|
1857 |
|
1858 return retval; |
|
1859 } |
|
1860 |
|
1861 static void |
3933
|
1862 gripe_unary_op_conversion_failed (const std::string& op, |
|
1863 const std::string& tn) |
3203
|
1864 { |
|
1865 error ("operator %s: type conversion for `%s' failed", |
|
1866 op.c_str (), tn.c_str ()); |
|
1867 } |
|
1868 |
3933
|
1869 const octave_value& |
|
1870 octave_value::do_non_const_unary_op (unary_op op) |
3203
|
1871 { |
|
1872 octave_value retval; |
|
1873 |
|
1874 int t = type_id (); |
|
1875 |
|
1876 non_const_unary_op_fcn f |
|
1877 = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1878 |
|
1879 if (f) |
|
1880 { |
|
1881 make_unique (); |
|
1882 |
|
1883 f (*rep); |
|
1884 } |
|
1885 else |
|
1886 { |
|
1887 type_conv_fcn cf = numeric_conversion_function (); |
|
1888 |
|
1889 if (cf) |
|
1890 { |
|
1891 octave_value *tmp = cf (*rep); |
|
1892 |
|
1893 if (tmp) |
|
1894 { |
|
1895 octave_value *old_rep = rep; |
|
1896 rep = tmp; |
|
1897 rep->count = 1; |
|
1898 |
|
1899 t = type_id (); |
|
1900 |
|
1901 f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1902 |
|
1903 if (f) |
|
1904 { |
|
1905 f (*rep); |
|
1906 |
|
1907 if (old_rep && --old_rep->count == 0) |
|
1908 delete old_rep; |
|
1909 } |
|
1910 else |
|
1911 { |
|
1912 if (old_rep) |
|
1913 { |
|
1914 if (--rep->count == 0) |
|
1915 delete rep; |
|
1916 |
|
1917 rep = old_rep; |
|
1918 } |
|
1919 |
|
1920 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1921 type_name ()); |
|
1922 } |
|
1923 } |
|
1924 else |
|
1925 gripe_unary_op_conversion_failed |
|
1926 (octave_value::unary_op_as_string (op), type_name ()); |
|
1927 } |
|
1928 else |
|
1929 gripe_unary_op (octave_value::unary_op_as_string (op), type_name ()); |
|
1930 } |
3933
|
1931 |
|
1932 return *this; |
3203
|
1933 } |
|
1934 |
3933
|
1935 #if 0 |
3205
|
1936 static void |
3933
|
1937 gripe_unary_op_failed_or_no_method (const std::string& on, |
|
1938 const std::string& tn) |
3205
|
1939 { |
|
1940 error ("operator %s: no method, or unable to evaluate for %s operand", |
|
1941 on.c_str (), tn.c_str ()); |
|
1942 } |
3933
|
1943 #endif |
3205
|
1944 |
|
1945 void |
4661
|
1946 octave_value::do_non_const_unary_op (unary_op, const octave_value_list&) |
3205
|
1947 { |
3933
|
1948 abort (); |
|
1949 } |
|
1950 |
|
1951 octave_value |
4247
|
1952 octave_value::do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
1953 const std::list<octave_value_list>& idx) |
3933
|
1954 { |
|
1955 octave_value retval; |
|
1956 |
|
1957 if (idx.empty ()) |
|
1958 { |
|
1959 do_non_const_unary_op (op); |
3205
|
1960 |
3933
|
1961 retval = *this; |
|
1962 } |
|
1963 else |
|
1964 { |
|
1965 // XXX FIXME XXX -- only do the following stuff if we can't find a |
|
1966 // specific function to call to handle the op= operation for the |
|
1967 // types we have. |
3205
|
1968 |
3933
|
1969 assign_op assop = unary_op_to_assign_op (op); |
|
1970 |
|
1971 retval = assign (assop, type, idx, 1.0); |
|
1972 } |
|
1973 |
|
1974 return retval; |
3205
|
1975 } |
|
1976 |
2903
|
1977 // Current indentation. |
|
1978 int octave_value::curr_print_indent_level = 0; |
|
1979 |
3018
|
1980 // TRUE means we are at the beginning of a line. |
2903
|
1981 bool octave_value::beginning_of_line = true; |
|
1982 |
|
1983 // Each print() function should call this before printing anything. |
|
1984 // |
|
1985 // This doesn't need to be fast, but isn't there a better way? |
|
1986 |
|
1987 void |
3523
|
1988 octave_value::indent (std::ostream& os) const |
2903
|
1989 { |
|
1990 assert (curr_print_indent_level >= 0); |
|
1991 |
|
1992 if (beginning_of_line) |
|
1993 { |
|
1994 // XXX FIXME XXX -- do we need this? |
|
1995 // os << prefix; |
|
1996 |
|
1997 for (int i = 0; i < curr_print_indent_level; i++) |
|
1998 os << " "; |
|
1999 |
|
2000 beginning_of_line = false; |
|
2001 } |
|
2002 } |
|
2003 |
|
2004 // All print() functions should use this to print new lines. |
|
2005 |
|
2006 void |
3523
|
2007 octave_value::newline (std::ostream& os) const |
2903
|
2008 { |
|
2009 os << "\n"; |
|
2010 |
|
2011 beginning_of_line = true; |
|
2012 } |
|
2013 |
|
2014 // For ressetting print state. |
|
2015 |
|
2016 void |
|
2017 octave_value::reset (void) const |
|
2018 { |
|
2019 beginning_of_line = true; |
|
2020 curr_print_indent_level = 0; |
|
2021 } |
|
2022 |
3205
|
2023 octave_value::assign_op |
|
2024 octave_value::unary_op_to_assign_op (unary_op op) |
|
2025 { |
|
2026 assign_op binop = unknown_assign_op; |
|
2027 |
|
2028 switch (op) |
|
2029 { |
3533
|
2030 case op_incr: |
|
2031 binop = op_add_eq; |
3205
|
2032 break; |
|
2033 |
3533
|
2034 case op_decr: |
|
2035 binop = op_sub_eq; |
3205
|
2036 break; |
|
2037 |
|
2038 default: |
|
2039 { |
3523
|
2040 std::string on = unary_op_as_string (op); |
3205
|
2041 error ("operator %s: no assign operator found", on.c_str ()); |
|
2042 } |
|
2043 } |
|
2044 |
|
2045 return binop; |
|
2046 } |
|
2047 |
3204
|
2048 octave_value::binary_op |
|
2049 octave_value::op_eq_to_binary_op (assign_op op) |
|
2050 { |
|
2051 binary_op binop = unknown_binary_op; |
|
2052 |
|
2053 switch (op) |
|
2054 { |
3533
|
2055 case op_add_eq: |
|
2056 binop = op_add; |
3204
|
2057 break; |
|
2058 |
3533
|
2059 case op_sub_eq: |
|
2060 binop = op_sub; |
3204
|
2061 break; |
|
2062 |
3533
|
2063 case op_mul_eq: |
|
2064 binop = op_mul; |
3204
|
2065 break; |
|
2066 |
3533
|
2067 case op_div_eq: |
|
2068 binop = op_div; |
3204
|
2069 break; |
|
2070 |
3533
|
2071 case op_ldiv_eq: |
|
2072 binop = op_ldiv; |
3204
|
2073 break; |
|
2074 |
4018
|
2075 case op_pow_eq: |
|
2076 binop = op_pow; |
|
2077 break; |
|
2078 |
3533
|
2079 case op_lshift_eq: |
|
2080 binop = op_lshift; |
3204
|
2081 break; |
|
2082 |
3533
|
2083 case op_rshift_eq: |
|
2084 binop = op_rshift; |
3204
|
2085 break; |
|
2086 |
3533
|
2087 case op_el_mul_eq: |
|
2088 binop = op_el_mul; |
3204
|
2089 break; |
|
2090 |
3533
|
2091 case op_el_div_eq: |
|
2092 binop = op_el_div; |
3204
|
2093 break; |
|
2094 |
3533
|
2095 case op_el_ldiv_eq: |
|
2096 binop = op_el_ldiv; |
3204
|
2097 break; |
|
2098 |
4018
|
2099 case op_el_pow_eq: |
|
2100 binop = op_el_pow; |
|
2101 break; |
|
2102 |
3533
|
2103 case op_el_and_eq: |
|
2104 binop = op_el_and; |
3204
|
2105 break; |
|
2106 |
3533
|
2107 case op_el_or_eq: |
|
2108 binop = op_el_or; |
3204
|
2109 break; |
|
2110 |
|
2111 default: |
|
2112 { |
3523
|
2113 std::string on = assign_op_as_string (op); |
3204
|
2114 error ("operator %s: no binary operator found", on.c_str ()); |
|
2115 } |
|
2116 } |
|
2117 |
|
2118 return binop; |
|
2119 } |
|
2120 |
3933
|
2121 octave_value |
|
2122 octave_value::empty_conv (const std::string& type, const octave_value& rhs) |
|
2123 { |
|
2124 octave_value retval; |
|
2125 |
|
2126 if (type.length () > 0) |
|
2127 { |
|
2128 switch (type[0]) |
|
2129 { |
|
2130 case '(': |
|
2131 { |
|
2132 if (type.length () > 1 && type[1] == '.') |
|
2133 retval = Octave_map (); |
|
2134 else |
|
2135 retval = octave_value (rhs.empty_clone ()); |
|
2136 } |
|
2137 break; |
|
2138 |
|
2139 case '{': |
|
2140 retval = Cell (); |
|
2141 break; |
|
2142 |
|
2143 case '.': |
|
2144 retval = Octave_map (); |
|
2145 break; |
|
2146 |
|
2147 default: |
|
2148 panic_impossible (); |
|
2149 } |
|
2150 } |
|
2151 else |
|
2152 retval = octave_value (rhs.empty_clone ()); |
|
2153 |
|
2154 return retval; |
|
2155 } |
|
2156 |
2376
|
2157 void |
|
2158 install_types (void) |
|
2159 { |
|
2160 octave_base_value::register_type (); |
3928
|
2161 octave_cell::register_type (); |
2376
|
2162 octave_scalar::register_type (); |
|
2163 octave_complex::register_type (); |
|
2164 octave_matrix::register_type (); |
|
2165 octave_complex_matrix::register_type (); |
|
2166 octave_range::register_type (); |
2825
|
2167 octave_bool::register_type (); |
|
2168 octave_bool_matrix::register_type (); |
2376
|
2169 octave_char_matrix::register_type (); |
|
2170 octave_char_matrix_str::register_type (); |
5279
|
2171 octave_char_matrix_sq_str::register_type (); |
4901
|
2172 octave_int8_scalar::register_type (); |
|
2173 octave_int16_scalar::register_type (); |
|
2174 octave_int32_scalar::register_type (); |
|
2175 octave_int64_scalar::register_type (); |
|
2176 octave_uint8_scalar::register_type (); |
|
2177 octave_uint16_scalar::register_type (); |
|
2178 octave_uint32_scalar::register_type (); |
|
2179 octave_uint64_scalar::register_type (); |
|
2180 octave_int8_matrix::register_type (); |
|
2181 octave_int16_matrix::register_type (); |
|
2182 octave_int32_matrix::register_type (); |
|
2183 octave_int64_matrix::register_type (); |
|
2184 octave_uint8_matrix::register_type (); |
|
2185 octave_uint16_matrix::register_type (); |
|
2186 octave_uint32_matrix::register_type (); |
|
2187 octave_uint64_matrix::register_type (); |
5164
|
2188 octave_sparse_bool_matrix::register_type (); |
|
2189 octave_sparse_matrix::register_type (); |
|
2190 octave_sparse_complex_matrix::register_type (); |
2376
|
2191 octave_struct::register_type (); |
2880
|
2192 octave_list::register_type (); |
3977
|
2193 octave_cs_list::register_type (); |
2376
|
2194 octave_all_va_args::register_type (); |
|
2195 octave_magic_colon::register_type (); |
2974
|
2196 octave_builtin::register_type (); |
|
2197 octave_mapper::register_type (); |
|
2198 octave_user_function::register_type (); |
4649
|
2199 octave_dld_function::register_type (); |
4643
|
2200 octave_fcn_handle::register_type (); |
4966
|
2201 octave_fcn_inline::register_type (); |
4643
|
2202 octave_streamoff::register_type (); |
2376
|
2203 } |
|
2204 |
4970
|
2205 #if 0 |
|
2206 DEFUN (cast, args, , |
|
2207 "-*- texinfo -*-\n\ |
|
2208 @deftypefn {Built-in Function} {} cast (@var{val}, @var{type})\n\ |
|
2209 Convert @var{val} to the new data type @var{type}.\n\ |
5642
|
2210 @seealso{class, typeinfo}\n\ |
|
2211 @end deftypefn") |
4970
|
2212 { |
|
2213 octave_value retval; |
|
2214 |
|
2215 if (args.length () == 2) |
|
2216 error ("cast: not implemented"); |
|
2217 else |
|
2218 print_usage ("cast"); |
|
2219 |
|
2220 return retval; |
|
2221 } |
|
2222 #endif |
|
2223 |
4791
|
2224 DEFUN (sizeof, args, , |
|
2225 "-*- texinfo -*-\n\ |
|
2226 @deftypefn {Built-in Function} {} sizeof (@var{val})\n\ |
|
2227 Return the size of @var{val} in bytes\n\ |
|
2228 @end deftypefn") |
|
2229 { |
|
2230 octave_value retval; |
|
2231 |
|
2232 if (args.length () == 1) |
|
2233 retval = args(0).byte_size (); |
|
2234 else |
|
2235 print_usage ("sizeof"); |
|
2236 |
|
2237 return retval; |
|
2238 } |
|
2239 |
2376
|
2240 static int |
4455
|
2241 warn_fortran_indexing (void) |
2376
|
2242 { |
4455
|
2243 Vwarn_fortran_indexing = check_preference ("warn_fortran_indexing"); |
2376
|
2244 |
4455
|
2245 liboctave_wfi_flag = Vwarn_fortran_indexing; |
2376
|
2246 |
|
2247 return 0; |
|
2248 } |
|
2249 |
|
2250 static int |
4452
|
2251 warn_imag_to_real (void) |
4257
|
2252 { |
4452
|
2253 Vwarn_imag_to_real = check_preference ("warn_imag_to_real"); |
4257
|
2254 |
|
2255 return 0; |
|
2256 } |
|
2257 |
|
2258 static int |
4452
|
2259 warn_num_to_str (void) |
2376
|
2260 { |
4452
|
2261 Vwarn_num_to_str = check_preference ("warn_num_to_str"); |
2376
|
2262 |
|
2263 return 0; |
|
2264 } |
|
2265 |
|
2266 static int |
4452
|
2267 warn_str_to_num (void) |
2376
|
2268 { |
4452
|
2269 Vwarn_str_to_num = check_preference ("warn_str_to_num"); |
2376
|
2270 |
|
2271 return 0; |
|
2272 } |
|
2273 |
|
2274 static int |
|
2275 print_answer_id_name (void) |
|
2276 { |
|
2277 Vprint_answer_id_name = check_preference ("print_answer_id_name"); |
|
2278 |
|
2279 return 0; |
|
2280 } |
|
2281 |
|
2282 static int |
4461
|
2283 warn_resize_on_range_error (void) |
2376
|
2284 { |
4461
|
2285 Vwarn_resize_on_range_error |
|
2286 = check_preference ("warn_resize_on_range_error"); |
2376
|
2287 |
4461
|
2288 liboctave_wrore_flag = Vwarn_resize_on_range_error; |
2376
|
2289 |
|
2290 return 0; |
|
2291 } |
|
2292 |
|
2293 static int |
4005
|
2294 silent_functions (void) |
|
2295 { |
|
2296 Vsilent_functions = check_preference ("silent_functions"); |
|
2297 |
|
2298 return 0; |
|
2299 } |
|
2300 |
|
2301 static int |
2376
|
2302 struct_levels_to_print (void) |
|
2303 { |
|
2304 double val; |
|
2305 if (builtin_real_scalar_variable ("struct_levels_to_print", val) |
|
2306 && ! xisnan (val)) |
|
2307 { |
|
2308 int ival = NINT (val); |
3961
|
2309 if (ival == val) |
2376
|
2310 { |
|
2311 Vstruct_levels_to_print = ival; |
|
2312 return 0; |
|
2313 } |
|
2314 } |
|
2315 gripe_invalid_value_specified ("struct_levels_to_print"); |
|
2316 return -1; |
|
2317 } |
|
2318 |
|
2319 static int |
|
2320 warn_divide_by_zero (void) |
|
2321 { |
|
2322 Vwarn_divide_by_zero = check_preference ("warn_divide_by_zero"); |
|
2323 |
|
2324 return 0; |
|
2325 } |
|
2326 |
|
2327 void |
2909
|
2328 symbols_of_ov (void) |
2376
|
2329 { |
4233
|
2330 DEFVAR (print_answer_id_name, true, print_answer_id_name, |
3372
|
2331 "-*- texinfo -*-\n\ |
|
2332 @defvr {Built-in Variable} print_answer_id_name\n\ |
|
2333 If the value of @code{print_answer_id_name} is nonzero, variable\n\ |
|
2334 names are printed along with the result. Otherwise, only the result\n\ |
|
2335 values are printed. The default value is 1.\n\ |
|
2336 @end defvr"); |
2376
|
2337 |
4233
|
2338 DEFVAR (silent_functions, false, silent_functions, |
4005
|
2339 "-*- texinfo -*-\n\ |
|
2340 @defvr {Built-in Variable} silent_functions\n\ |
|
2341 If the value of @code{silent_functions} is nonzero, internal output\n\ |
|
2342 from a function is suppressed. Otherwise, the results of expressions\n\ |
|
2343 within a function body that are not terminated with a semicolon will\n\ |
|
2344 have their values printed. The default value is 0.\n\ |
|
2345 \n\ |
|
2346 For example, if the function\n\ |
|
2347 \n\ |
|
2348 @example\n\ |
|
2349 function f ()\n\ |
|
2350 2 + 2\n\ |
|
2351 endfunction\n\ |
|
2352 @end example\n\ |
|
2353 \n\ |
|
2354 @noindent\n\ |
|
2355 is executed, Octave will either print @samp{ans = 4} or nothing\n\ |
|
2356 depending on the value of @code{silent_functions}.\n\ |
|
2357 @end defvr"); |
|
2358 |
3258
|
2359 DEFVAR (struct_levels_to_print, 2.0, struct_levels_to_print, |
3361
|
2360 "-*- texinfo -*-\n\ |
|
2361 @defvr {Built-in Variable} struct_levels_to_print\n\ |
|
2362 You can tell Octave how many structure levels to display by setting the\n\ |
|
2363 built-in variable @code{struct_levels_to_print}. The default value is 2.\n\ |
3363
|
2364 @end defvr"); |
2376
|
2365 |
4233
|
2366 DEFVAR (warn_divide_by_zero, true, warn_divide_by_zero, |
3371
|
2367 "-*- texinfo -*-\n\ |
|
2368 @defvr {Built-in Variable} warn_divide_by_zero\n\ |
|
2369 If the value of @code{warn_divide_by_zero} is nonzero, a warning\n\ |
|
2370 is issued when Octave encounters a division by zero. If the value is\n\ |
|
2371 0, the warning is omitted. The default value is 1.\n\ |
|
2372 @end defvr"); |
4451
|
2373 |
4455
|
2374 DEFVAR (warn_fortran_indexing, false, warn_fortran_indexing, |
|
2375 "-*- texinfo -*-\n\ |
|
2376 @defvr {Built-in Variable} warn_fortran_indexing\n\ |
|
2377 If the value of @code{warn_fortran_indexing} is nonzero, a warning is\n\ |
|
2378 printed for expressions which select elements of a two-dimensional matrix\n\ |
|
2379 using a single index. The default value is 0.\n\ |
|
2380 @end defvr"); |
|
2381 |
4451
|
2382 DEFVAR (warn_imag_to_real, false, warn_imag_to_real, |
|
2383 "-*- texinfo -*-\n\ |
|
2384 @defvr {Built-in Variable} warn_imag_to_real\n\ |
|
2385 If the value of @code{warn_imag_to_real} is nonzero, a warning is\n\ |
|
2386 printed for implicit conversions of complex numbers to real numbers.\n\ |
|
2387 The default value is 0.\n\ |
|
2388 @end defvr"); |
4452
|
2389 |
|
2390 DEFVAR (warn_num_to_str, true, warn_num_to_str, |
|
2391 "-*- texinfo -*-\n\ |
|
2392 @defvr {Built-in Variable} warn_num_to_str\n\ |
|
2393 If the value of @code{warn_num_to_str} is nonzero, a warning is\n\ |
|
2394 printed for implicit conversions of numbers to their ASCII character\n\ |
|
2395 equivalents when strings are constructed using a mixture of strings and\n\ |
|
2396 numbers in matrix notation. For example,\n\ |
|
2397 \n\ |
|
2398 @example\n\ |
|
2399 @group\n\ |
|
2400 [ \"f\", 111, 111 ]\n\ |
|
2401 @result{} \"foo\"\n\ |
|
2402 @end group\n\ |
|
2403 @end example\n\ |
|
2404 elicits a warning if @code{warn_num_to_str} is nonzero. The default\n\ |
|
2405 value is 1.\n\ |
|
2406 @end defvr"); |
|
2407 |
4461
|
2408 DEFVAR (warn_resize_on_range_error, false, warn_resize_on_range_error, |
|
2409 "-*- texinfo -*-\n\ |
|
2410 @defvr {Built-in Variable} warn_resize_on_range_error\n\ |
|
2411 If the value of @code{warn_resize_on_range_error} is nonzero, print a\n\ |
|
2412 warning when a matrix is resized by an indexed assignment with\n\ |
|
2413 indices outside the current bounds. The default value is 0.\n\ |
|
2414 @end defvr"); |
|
2415 |
4452
|
2416 DEFVAR (warn_str_to_num, false, warn_str_to_num, |
|
2417 "-*- texinfo -*-\n\ |
|
2418 @defvr {Built-in Variable} warn_str_to_num\n\ |
|
2419 If the value of @code{warn_str_to_num} is nonzero, a warning is printed\n\ |
|
2420 for implicit conversions of strings to their numeric ASCII equivalents.\n\ |
|
2421 For example,\n\ |
|
2422 @example\n\ |
|
2423 @group\n\ |
|
2424 \"abc\" + 0\n\ |
|
2425 @result{} 97 98 99\n\ |
|
2426 @end group\n\ |
|
2427 @end example\n\ |
|
2428 elicits a warning if @code{warn_str_to_num} is nonzero. The default\n\ |
|
2429 value is 0.\n\ |
|
2430 @end defvr"); |
2376
|
2431 } |
|
2432 |
|
2433 /* |
|
2434 ;;; Local Variables: *** |
|
2435 ;;; mode: C++ *** |
|
2436 ;;; End: *** |
|
2437 */ |