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