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