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