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