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