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