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