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 |
4455
|
85 // If TRUE, print a warning for assignments like |
2376
|
86 // |
|
87 // octave> A(1) = 3; A(2) = 5 |
|
88 // |
|
89 // for A already defined and a matrix type. |
4455
|
90 bool Vwarn_fortran_indexing; |
2376
|
91 |
4452
|
92 // Should we warn about conversions from complex to real? |
|
93 int Vwarn_imag_to_real; |
4257
|
94 |
2880
|
95 // XXX FIXME XXX |
|
96 |
2376
|
97 // Octave's value type. |
|
98 |
3536
|
99 std::string |
3203
|
100 octave_value::unary_op_as_string (unary_op op) |
|
101 { |
3523
|
102 std::string retval; |
3203
|
103 |
|
104 switch (op) |
|
105 { |
3533
|
106 case op_not: |
3203
|
107 retval = "!"; |
|
108 break; |
|
109 |
4965
|
110 case op_uplus: |
|
111 retval = "+"; |
|
112 break; |
|
113 |
3533
|
114 case op_uminus: |
3203
|
115 retval = "-"; |
|
116 break; |
|
117 |
3533
|
118 case op_transpose: |
3203
|
119 retval = ".'"; |
|
120 break; |
|
121 |
3533
|
122 case op_hermitian: |
3203
|
123 retval = "'"; |
|
124 break; |
|
125 |
3533
|
126 case op_incr: |
3203
|
127 retval = "++"; |
|
128 break; |
|
129 |
3533
|
130 case op_decr: |
3203
|
131 retval = "--"; |
|
132 break; |
|
133 |
|
134 default: |
|
135 retval = "<unknown>"; |
|
136 } |
|
137 |
|
138 return retval; |
|
139 } |
|
140 |
3536
|
141 std::string |
2376
|
142 octave_value::binary_op_as_string (binary_op op) |
|
143 { |
3523
|
144 std::string retval; |
2376
|
145 |
|
146 switch (op) |
|
147 { |
3533
|
148 case op_add: |
2376
|
149 retval = "+"; |
|
150 break; |
|
151 |
3533
|
152 case op_sub: |
2376
|
153 retval = "-"; |
|
154 break; |
|
155 |
3533
|
156 case op_mul: |
2376
|
157 retval = "*"; |
|
158 break; |
|
159 |
3533
|
160 case op_div: |
2376
|
161 retval = "/"; |
|
162 break; |
|
163 |
3533
|
164 case op_pow: |
2376
|
165 retval = "^"; |
|
166 break; |
|
167 |
3533
|
168 case op_ldiv: |
2376
|
169 retval = "\\"; |
|
170 break; |
|
171 |
3533
|
172 case op_lshift: |
2903
|
173 retval = "<<"; |
|
174 break; |
|
175 |
3533
|
176 case op_rshift: |
2903
|
177 retval = ">>"; |
|
178 break; |
|
179 |
3533
|
180 case op_lt: |
2376
|
181 retval = "<"; |
|
182 break; |
|
183 |
3533
|
184 case op_le: |
2376
|
185 retval = "<="; |
|
186 break; |
|
187 |
3533
|
188 case op_eq: |
2376
|
189 retval = "=="; |
|
190 break; |
|
191 |
3533
|
192 case op_ge: |
2376
|
193 retval = ">="; |
|
194 break; |
|
195 |
3533
|
196 case op_gt: |
2376
|
197 retval = ">"; |
|
198 break; |
|
199 |
3533
|
200 case op_ne: |
2376
|
201 retval = "!="; |
|
202 break; |
|
203 |
3533
|
204 case op_el_mul: |
2376
|
205 retval = ".*"; |
|
206 break; |
|
207 |
3533
|
208 case op_el_div: |
2376
|
209 retval = "./"; |
|
210 break; |
|
211 |
3533
|
212 case op_el_pow: |
2376
|
213 retval = ".^"; |
|
214 break; |
|
215 |
3533
|
216 case op_el_ldiv: |
2376
|
217 retval = ".\\"; |
|
218 break; |
|
219 |
3533
|
220 case op_el_and: |
2376
|
221 retval = "&"; |
|
222 break; |
|
223 |
3533
|
224 case op_el_or: |
2376
|
225 retval = "|"; |
|
226 break; |
|
227 |
3533
|
228 case op_struct_ref: |
2376
|
229 retval = "."; |
|
230 break; |
|
231 |
|
232 default: |
|
233 retval = "<unknown>"; |
|
234 } |
|
235 |
|
236 return retval; |
|
237 } |
|
238 |
3536
|
239 std::string |
2880
|
240 octave_value::assign_op_as_string (assign_op op) |
|
241 { |
3523
|
242 std::string retval; |
2880
|
243 |
|
244 switch (op) |
|
245 { |
3533
|
246 case op_asn_eq: |
2880
|
247 retval = "="; |
|
248 break; |
|
249 |
3533
|
250 case op_add_eq: |
2880
|
251 retval = "+="; |
|
252 break; |
|
253 |
3533
|
254 case op_sub_eq: |
2880
|
255 retval = "-="; |
|
256 break; |
|
257 |
3533
|
258 case op_mul_eq: |
2880
|
259 retval = "*="; |
|
260 break; |
|
261 |
3533
|
262 case op_div_eq: |
2880
|
263 retval = "/="; |
|
264 break; |
|
265 |
3533
|
266 case op_ldiv_eq: |
3204
|
267 retval = "\\="; |
|
268 break; |
|
269 |
4018
|
270 case op_pow_eq: |
|
271 retval = "^="; |
|
272 break; |
|
273 |
3533
|
274 case op_lshift_eq: |
2903
|
275 retval = "<<="; |
|
276 break; |
|
277 |
3533
|
278 case op_rshift_eq: |
2903
|
279 retval = ">>="; |
|
280 break; |
|
281 |
3533
|
282 case op_el_mul_eq: |
2880
|
283 retval = ".*="; |
|
284 break; |
|
285 |
3533
|
286 case op_el_div_eq: |
2880
|
287 retval = "./="; |
|
288 break; |
|
289 |
3533
|
290 case op_el_ldiv_eq: |
3204
|
291 retval = ".\\="; |
|
292 break; |
|
293 |
4018
|
294 case op_el_pow_eq: |
|
295 retval = ".^="; |
|
296 break; |
|
297 |
3533
|
298 case op_el_and_eq: |
2880
|
299 retval = "&="; |
|
300 break; |
|
301 |
3533
|
302 case op_el_or_eq: |
2880
|
303 retval = "|="; |
|
304 break; |
|
305 |
|
306 default: |
|
307 retval = "<unknown>"; |
|
308 } |
|
309 |
|
310 return retval; |
|
311 } |
|
312 |
5759
|
313 octave_value::octave_value (void) |
|
314 : rep (new octave_base_value ()) |
4513
|
315 { |
2825
|
316 } |
2376
|
317 |
4254
|
318 octave_value::octave_value (short int i) |
|
319 : rep (new octave_scalar (i)) |
|
320 { |
|
321 } |
|
322 |
|
323 octave_value::octave_value (unsigned short int i) |
|
324 : rep (new octave_scalar (i)) |
|
325 { |
|
326 } |
|
327 |
4233
|
328 octave_value::octave_value (int i) |
|
329 : rep (new octave_scalar (i)) |
|
330 { |
|
331 } |
|
332 |
4254
|
333 octave_value::octave_value (unsigned int i) |
|
334 : rep (new octave_scalar (i)) |
|
335 { |
|
336 } |
|
337 |
|
338 octave_value::octave_value (long int i) |
|
339 : rep (new octave_scalar (i)) |
|
340 { |
|
341 } |
|
342 |
|
343 octave_value::octave_value (unsigned long int i) |
|
344 : rep (new octave_scalar (i)) |
|
345 { |
|
346 } |
|
347 |
4353
|
348 #if defined (HAVE_LONG_LONG_INT) |
|
349 octave_value::octave_value (long long int i) |
|
350 : rep (new octave_scalar (i)) |
|
351 { |
|
352 } |
|
353 #endif |
|
354 |
4355
|
355 #if defined (HAVE_UNSIGNED_LONG_LONG_INT) |
4353
|
356 octave_value::octave_value (unsigned long long int i) |
|
357 : rep (new octave_scalar (i)) |
|
358 { |
|
359 } |
|
360 #endif |
|
361 |
4254
|
362 octave_value::octave_value (octave_time t) |
|
363 : rep (new octave_scalar (t)) |
|
364 { |
|
365 } |
|
366 |
2376
|
367 octave_value::octave_value (double d) |
2825
|
368 : rep (new octave_scalar (d)) |
|
369 { |
|
370 } |
2376
|
371 |
4587
|
372 octave_value::octave_value (const Cell& c, bool is_csl) |
5477
|
373 : rep (is_csl |
5759
|
374 ? dynamic_cast<octave_base_value *> (new octave_cs_list (c)) |
|
375 : dynamic_cast<octave_base_value *> (new octave_cell (c))) |
3351
|
376 { |
|
377 } |
|
378 |
5147
|
379 octave_value::octave_value (const ArrayN<octave_value>& a, bool is_csl) |
5477
|
380 : rep (is_csl |
5759
|
381 ? dynamic_cast<octave_base_value *> (new octave_cs_list (Cell (a))) |
|
382 : dynamic_cast<octave_base_value *> (new octave_cell (Cell (a)))) |
5147
|
383 { |
|
384 } |
|
385 |
2376
|
386 octave_value::octave_value (const Matrix& m) |
2423
|
387 : rep (new octave_matrix (m)) |
|
388 { |
|
389 maybe_mutate (); |
|
390 } |
2376
|
391 |
4507
|
392 octave_value::octave_value (const NDArray& a) |
4513
|
393 : rep (new octave_matrix (a)) |
4478
|
394 { |
|
395 maybe_mutate (); |
|
396 } |
|
397 |
4911
|
398 octave_value::octave_value (const ArrayN<double>& a) |
|
399 : rep (new octave_matrix (a)) |
|
400 { |
|
401 maybe_mutate (); |
|
402 } |
|
403 |
2376
|
404 octave_value::octave_value (const DiagMatrix& d) |
2423
|
405 : rep (new octave_matrix (d)) |
|
406 { |
|
407 maybe_mutate (); |
|
408 } |
2376
|
409 |
3418
|
410 octave_value::octave_value (const RowVector& v) |
|
411 : rep (new octave_matrix (v)) |
2423
|
412 { |
|
413 maybe_mutate (); |
|
414 } |
2376
|
415 |
3418
|
416 octave_value::octave_value (const ColumnVector& v) |
|
417 : rep (new octave_matrix (v)) |
2423
|
418 { |
|
419 maybe_mutate (); |
|
420 } |
2376
|
421 |
|
422 octave_value::octave_value (const Complex& C) |
2423
|
423 : rep (new octave_complex (C)) |
|
424 { |
|
425 maybe_mutate (); |
|
426 } |
2376
|
427 |
|
428 octave_value::octave_value (const ComplexMatrix& m) |
2423
|
429 : rep (new octave_complex_matrix (m)) |
|
430 { |
|
431 maybe_mutate (); |
|
432 } |
2376
|
433 |
4513
|
434 octave_value::octave_value (const ComplexNDArray& a) |
|
435 : rep (new octave_complex_matrix (a)) |
4478
|
436 { |
|
437 maybe_mutate (); |
|
438 } |
|
439 |
4911
|
440 octave_value::octave_value (const ArrayN<Complex>& a) |
|
441 : rep (new octave_complex_matrix (a)) |
|
442 { |
|
443 maybe_mutate (); |
|
444 } |
|
445 |
2376
|
446 octave_value::octave_value (const ComplexDiagMatrix& d) |
2423
|
447 : rep (new octave_complex_matrix (d)) |
|
448 { |
|
449 maybe_mutate (); |
|
450 } |
2376
|
451 |
3418
|
452 octave_value::octave_value (const ComplexRowVector& v) |
|
453 : rep (new octave_complex_matrix (v)) |
2423
|
454 { |
|
455 maybe_mutate (); |
|
456 } |
2376
|
457 |
3418
|
458 octave_value::octave_value (const ComplexColumnVector& v) |
|
459 : rep (new octave_complex_matrix (v)) |
2423
|
460 { |
|
461 maybe_mutate (); |
|
462 } |
2376
|
463 |
2825
|
464 octave_value::octave_value (bool b) |
|
465 : rep (new octave_bool (b)) |
|
466 { |
|
467 } |
|
468 |
|
469 octave_value::octave_value (const boolMatrix& bm) |
|
470 : rep (new octave_bool_matrix (bm)) |
|
471 { |
|
472 maybe_mutate (); |
|
473 } |
|
474 |
4513
|
475 octave_value::octave_value (const boolNDArray& bnda) |
|
476 : rep (new octave_bool_matrix (bnda)) |
|
477 { |
|
478 maybe_mutate (); |
|
479 } |
|
480 |
5279
|
481 octave_value::octave_value (char c, char type) |
|
482 : rep (type == '"' |
|
483 ? new octave_char_matrix_dq_str (c) |
|
484 : new octave_char_matrix_sq_str (c)) |
3189
|
485 { |
|
486 maybe_mutate (); |
|
487 } |
|
488 |
5279
|
489 octave_value::octave_value (const char *s, char type) |
|
490 : rep (type == '"' |
|
491 ? new octave_char_matrix_dq_str (s) |
|
492 : new octave_char_matrix_sq_str (s)) |
2423
|
493 { |
|
494 maybe_mutate (); |
|
495 } |
2376
|
496 |
5279
|
497 octave_value::octave_value (const std::string& s, char type) |
|
498 : rep (type == '"' |
|
499 ? new octave_char_matrix_dq_str (s) |
|
500 : new octave_char_matrix_sq_str (s)) |
2423
|
501 { |
|
502 maybe_mutate (); |
|
503 } |
2376
|
504 |
5279
|
505 octave_value::octave_value (const string_vector& s, char type) |
|
506 : rep (type == '"' |
|
507 ? new octave_char_matrix_dq_str (s) |
|
508 : new octave_char_matrix_sq_str (s)) |
2423
|
509 { |
|
510 maybe_mutate (); |
|
511 } |
2376
|
512 |
5279
|
513 octave_value::octave_value (const charMatrix& chm, bool is_str, char type) |
4587
|
514 : rep (is_str |
5279
|
515 ? (type == '"' |
|
516 ? new octave_char_matrix_dq_str (chm) |
|
517 : new octave_char_matrix_sq_str (chm)) |
4513
|
518 : new octave_char_matrix (chm)) |
2409
|
519 { |
4513
|
520 maybe_mutate (); |
|
521 } |
2376
|
522 |
5279
|
523 octave_value::octave_value (const charNDArray& chm, bool is_str, char type) |
4587
|
524 : rep (is_str |
5279
|
525 ? (type == '"' |
|
526 ? new octave_char_matrix_dq_str (chm) |
|
527 : new octave_char_matrix_sq_str (chm)) |
4513
|
528 : new octave_char_matrix (chm)) |
|
529 { |
2423
|
530 maybe_mutate (); |
2409
|
531 } |
2376
|
532 |
5279
|
533 octave_value::octave_value (const ArrayN<char>& chm, bool is_str, char type) |
4997
|
534 : rep (is_str |
5279
|
535 ? (type == '"' |
|
536 ? new octave_char_matrix_dq_str (chm) |
|
537 : new octave_char_matrix_sq_str (chm)) |
4997
|
538 : new octave_char_matrix (chm)) |
|
539 { |
|
540 maybe_mutate (); |
|
541 } |
|
542 |
5164
|
543 octave_value::octave_value (const SparseMatrix& m, const SparseType &t) |
|
544 : rep (new octave_sparse_matrix (m, t)) |
|
545 { |
|
546 maybe_mutate (); |
|
547 } |
|
548 |
|
549 octave_value::octave_value (const SparseComplexMatrix& m, const SparseType &t) |
|
550 : rep (new octave_sparse_complex_matrix (m, t)) |
|
551 { |
|
552 maybe_mutate (); |
|
553 } |
|
554 |
|
555 octave_value::octave_value (const SparseBoolMatrix& bm, const SparseType &t) |
|
556 : rep (new octave_sparse_bool_matrix (bm, t)) |
|
557 { |
|
558 maybe_mutate (); |
|
559 } |
|
560 |
4901
|
561 octave_value::octave_value (const octave_int8& i) |
|
562 : rep (new octave_int8_scalar (i)) |
|
563 { |
|
564 maybe_mutate (); |
|
565 } |
|
566 |
|
567 octave_value::octave_value (const octave_uint8& i) |
|
568 : rep (new octave_uint8_scalar (i)) |
|
569 { |
|
570 maybe_mutate (); |
|
571 } |
|
572 |
|
573 octave_value::octave_value (const octave_int16& i) |
|
574 : rep (new octave_int16_scalar (i)) |
|
575 { |
|
576 maybe_mutate (); |
|
577 } |
|
578 |
|
579 octave_value::octave_value (const octave_uint16& i) |
|
580 : rep (new octave_uint16_scalar (i)) |
|
581 { |
|
582 maybe_mutate (); |
|
583 } |
|
584 |
|
585 octave_value::octave_value (const octave_int32& i) |
|
586 : rep (new octave_int32_scalar (i)) |
|
587 { |
|
588 maybe_mutate (); |
|
589 } |
|
590 |
|
591 octave_value::octave_value (const octave_uint32& i) |
|
592 : rep (new octave_uint32_scalar (i)) |
|
593 { |
|
594 maybe_mutate (); |
|
595 } |
|
596 |
|
597 octave_value::octave_value (const octave_int64& i) |
|
598 : rep (new octave_int64_scalar (i)) |
|
599 { |
|
600 maybe_mutate (); |
|
601 } |
|
602 |
|
603 octave_value::octave_value (const octave_uint64& i) |
|
604 : rep (new octave_uint64_scalar (i)) |
|
605 { |
|
606 maybe_mutate (); |
|
607 } |
|
608 |
|
609 octave_value::octave_value (const int8NDArray& inda) |
|
610 : rep (new octave_int8_matrix (inda)) |
|
611 { |
|
612 maybe_mutate (); |
|
613 } |
|
614 |
|
615 octave_value::octave_value (const uint8NDArray& inda) |
|
616 : rep (new octave_uint8_matrix (inda)) |
|
617 { |
|
618 maybe_mutate (); |
|
619 } |
|
620 |
|
621 octave_value::octave_value (const int16NDArray& inda) |
|
622 : rep (new octave_int16_matrix (inda)) |
|
623 { |
|
624 maybe_mutate (); |
|
625 } |
|
626 |
|
627 octave_value::octave_value (const uint16NDArray& inda) |
|
628 : rep (new octave_uint16_matrix (inda)) |
|
629 { |
|
630 maybe_mutate (); |
|
631 } |
|
632 |
|
633 octave_value::octave_value (const int32NDArray& inda) |
|
634 : rep (new octave_int32_matrix (inda)) |
|
635 { |
|
636 maybe_mutate (); |
|
637 } |
|
638 |
|
639 octave_value::octave_value (const uint32NDArray& inda) |
|
640 : rep (new octave_uint32_matrix (inda)) |
|
641 { |
|
642 maybe_mutate (); |
|
643 } |
|
644 |
|
645 octave_value::octave_value (const int64NDArray& inda) |
|
646 : rep (new octave_int64_matrix (inda)) |
|
647 { |
|
648 maybe_mutate (); |
|
649 } |
|
650 |
|
651 octave_value::octave_value (const uint64NDArray& inda) |
|
652 : rep (new octave_uint64_matrix (inda)) |
|
653 { |
|
654 maybe_mutate (); |
|
655 } |
|
656 |
2376
|
657 octave_value::octave_value (double base, double limit, double inc) |
2423
|
658 : rep (new octave_range (base, limit, inc)) |
|
659 { |
|
660 maybe_mutate (); |
|
661 } |
2376
|
662 |
|
663 octave_value::octave_value (const Range& r) |
2423
|
664 : rep (new octave_range (r)) |
|
665 { |
|
666 maybe_mutate (); |
|
667 } |
2376
|
668 |
|
669 octave_value::octave_value (const Octave_map& m) |
2825
|
670 : rep (new octave_struct (m)) |
|
671 { |
2880
|
672 } |
|
673 |
4643
|
674 octave_value::octave_value (const streamoff_array& off) |
|
675 : rep (new octave_streamoff (off)) |
|
676 { |
|
677 } |
|
678 |
4587
|
679 octave_value::octave_value (const octave_value_list& l, bool is_csl) |
5477
|
680 : rep (is_csl |
5759
|
681 ? dynamic_cast<octave_base_value *> (new octave_cs_list (l)) |
|
682 : dynamic_cast<octave_base_value *> (new octave_list (l))) |
2880
|
683 { |
|
684 } |
2376
|
685 |
|
686 octave_value::octave_value (octave_value::magic_colon) |
2825
|
687 : rep (new octave_magic_colon ()) |
|
688 { |
|
689 } |
2376
|
690 |
|
691 octave_value::octave_value (octave_value::all_va_args) |
2825
|
692 : rep (new octave_all_va_args ()) |
|
693 { |
|
694 } |
2376
|
695 |
5759
|
696 octave_value::octave_value (octave_base_value *new_rep) |
2825
|
697 : rep (new_rep) |
|
698 { |
|
699 } |
2376
|
700 |
|
701 octave_value::~octave_value (void) |
|
702 { |
|
703 #if defined (MDEBUG) |
5759
|
704 std::cerr << "~octave_value: rep: " << rep |
|
705 << " rep->count: " << rep->count << std::endl; |
2376
|
706 #endif |
|
707 |
5759
|
708 if (--rep->count == 0) |
|
709 delete rep; |
2376
|
710 } |
|
711 |
5759
|
712 octave_base_value * |
3933
|
713 octave_value::clone (void) const |
2880
|
714 { |
|
715 panic_impossible (); |
3546
|
716 return 0; |
2880
|
717 } |
|
718 |
2409
|
719 void |
|
720 octave_value::maybe_mutate (void) |
|
721 { |
5759
|
722 octave_base_value *tmp = rep->try_narrowing_conversion (); |
2409
|
723 |
|
724 if (tmp && tmp != rep) |
|
725 { |
|
726 if (--rep->count == 0) |
|
727 delete rep; |
|
728 |
|
729 rep = tmp; |
|
730 } |
|
731 } |
|
732 |
4247
|
733 octave_value |
4271
|
734 octave_value::single_subsref (const std::string& type, |
|
735 const octave_value_list& idx) |
4247
|
736 { |
|
737 std::list<octave_value_list> i; |
|
738 |
|
739 i.push_back (idx); |
|
740 |
|
741 return rep->subsref (type, i); |
|
742 } |
|
743 |
2974
|
744 octave_value_list |
4247
|
745 octave_value::subsref (const std::string& type, |
4219
|
746 const std::list<octave_value_list>& idx, int nargout) |
3933
|
747 { |
|
748 if (is_constant ()) |
|
749 return rep->subsref (type, idx); |
|
750 else |
|
751 return rep->subsref (type, idx, nargout); |
|
752 } |
|
753 |
|
754 octave_value |
4247
|
755 octave_value::next_subsref (const std::string& type, |
4219
|
756 const std::list<octave_value_list>& idx, |
4233
|
757 size_t skip) |
3933
|
758 { |
4582
|
759 if (! error_state && idx.size () > skip) |
3933
|
760 { |
4219
|
761 std::list<octave_value_list> new_idx (idx); |
4233
|
762 for (size_t i = 0; i < skip; i++) |
4219
|
763 new_idx.erase (new_idx.begin ()); |
3933
|
764 return subsref (type.substr (skip), new_idx); |
|
765 } |
|
766 else |
|
767 return *this; |
|
768 } |
|
769 |
|
770 octave_value_list |
4994
|
771 octave_value::next_subsref (int nargout, const std::string& type, |
|
772 const std::list<octave_value_list>& idx, |
|
773 size_t skip) |
|
774 { |
|
775 if (! error_state && idx.size () > skip) |
|
776 { |
|
777 std::list<octave_value_list> new_idx (idx); |
|
778 for (size_t i = 0; i < skip; i++) |
|
779 new_idx.erase (new_idx.begin ()); |
|
780 return subsref (type.substr (skip), new_idx, nargout); |
|
781 } |
|
782 else |
|
783 return *this; |
|
784 } |
|
785 |
|
786 octave_value_list |
3544
|
787 octave_value::do_multi_index_op (int nargout, const octave_value_list& idx) |
2974
|
788 { |
3544
|
789 return rep->do_multi_index_op (nargout, idx); |
2974
|
790 } |
|
791 |
3933
|
792 #if 0 |
3204
|
793 static void |
3933
|
794 gripe_assign_failed (const std::string& on, const std::string& tn1, |
|
795 const std::string& tn2) |
3204
|
796 { |
|
797 error ("assignment failed for `%s %s %s'", |
|
798 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
799 } |
3933
|
800 #endif |
3204
|
801 |
|
802 static void |
3933
|
803 gripe_assign_failed_or_no_method (const std::string& on, |
|
804 const std::string& tn1, |
3523
|
805 const std::string& tn2) |
3204
|
806 { |
|
807 error ("assignment failed, or no method for `%s %s %s'", |
|
808 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
809 } |
|
810 |
3933
|
811 octave_value |
4247
|
812 octave_value::subsasgn (const std::string& type, |
4219
|
813 const std::list<octave_value_list>& idx, |
3933
|
814 const octave_value& rhs) |
|
815 { |
|
816 return rep->subsasgn (type, idx, rhs); |
|
817 } |
|
818 |
|
819 octave_value |
4247
|
820 octave_value::assign (assign_op op, const std::string& type, |
4219
|
821 const std::list<octave_value_list>& idx, |
3933
|
822 const octave_value& rhs) |
|
823 { |
|
824 octave_value retval; |
|
825 |
|
826 make_unique (); |
|
827 |
|
828 octave_value t_rhs = rhs; |
|
829 |
|
830 if (op != op_asn_eq) |
|
831 { |
|
832 // XXX FIXME XXX -- only do the following stuff if we can't find |
|
833 // a specific function to call to handle the op= operation for |
|
834 // the types we have. |
|
835 |
5001
|
836 octave_value t; |
|
837 if (is_constant ()) |
|
838 t = subsref (type, idx); |
|
839 else |
|
840 { |
|
841 octave_value_list tl = subsref (type, idx, 1); |
|
842 if (tl.length () > 0) |
|
843 t = tl(0); |
|
844 } |
3933
|
845 |
|
846 if (! error_state) |
|
847 { |
|
848 binary_op binop = op_eq_to_binary_op (op); |
|
849 |
|
850 if (! error_state) |
|
851 t_rhs = do_binary_op (binop, t, rhs); |
|
852 } |
|
853 } |
|
854 |
|
855 if (! error_state) |
|
856 { |
|
857 if (type[0] == '.' && ! is_map ()) |
|
858 { |
|
859 octave_value tmp = Octave_map (); |
|
860 retval = tmp.subsasgn (type, idx, t_rhs); |
|
861 } |
|
862 else |
|
863 retval = subsasgn (type, idx, t_rhs); |
|
864 } |
|
865 |
|
866 if (error_state) |
|
867 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
868 type_name (), rhs.type_name ()); |
|
869 |
|
870 return retval; |
|
871 } |
|
872 |
|
873 const octave_value& |
3203
|
874 octave_value::assign (assign_op op, const octave_value& rhs) |
2880
|
875 { |
3533
|
876 if (op == op_asn_eq) |
3203
|
877 operator = (rhs); |
|
878 else |
|
879 { |
3204
|
880 // XXX FIXME XXX -- only do the following stuff if we can't find |
|
881 // a specific function to call to handle the op= operation for |
|
882 // the types we have. |
|
883 |
|
884 binary_op binop = op_eq_to_binary_op (op); |
|
885 |
|
886 if (! error_state) |
|
887 { |
|
888 octave_value t = do_binary_op (binop, *this, rhs); |
|
889 |
|
890 if (! error_state) |
|
891 operator = (t); |
|
892 } |
|
893 |
|
894 if (error_state) |
|
895 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
896 type_name (), rhs.type_name ()); |
|
897 } |
|
898 |
3933
|
899 return *this; |
2376
|
900 } |
|
901 |
5275
|
902 octave_idx_type |
4563
|
903 octave_value::length (void) const |
|
904 { |
|
905 int retval = 0; |
|
906 |
|
907 dim_vector dv = dims (); |
4584
|
908 |
4563
|
909 for (int i = 0; i < dv.length (); i++) |
|
910 { |
|
911 if (dv(i) < 0) |
|
912 { |
|
913 retval = -1; |
|
914 break; |
|
915 } |
|
916 |
4584
|
917 if (dv(i) == 0) |
|
918 { |
|
919 retval = 0; |
|
920 break; |
|
921 } |
|
922 |
4563
|
923 if (dv(i) > retval) |
|
924 retval = dv(i); |
|
925 } |
|
926 |
|
927 return retval; |
|
928 } |
|
929 |
5659
|
930 Matrix |
|
931 octave_value::size (void) const |
|
932 { |
|
933 dim_vector dv = dims (); |
|
934 |
|
935 int n_dims = dv.length (); |
|
936 |
|
937 Matrix retval (1, n_dims); |
|
938 |
|
939 while (n_dims--) |
|
940 retval(n_dims) = dv(n_dims); |
|
941 |
|
942 return retval; |
|
943 } |
|
944 |
3351
|
945 Cell |
|
946 octave_value::cell_value (void) const |
|
947 { |
|
948 return rep->cell_value (); |
|
949 } |
|
950 |
2376
|
951 Octave_map |
|
952 octave_value::map_value (void) const |
|
953 { |
|
954 return rep->map_value (); |
|
955 } |
|
956 |
4645
|
957 std::streamoff |
4643
|
958 octave_value::streamoff_value (void) const |
|
959 { |
|
960 return rep->streamoff_value (); |
|
961 } |
|
962 |
4645
|
963 streamoff_array |
|
964 octave_value::streamoff_array_value (void) const |
|
965 { |
|
966 return rep->streamoff_array_value (); |
|
967 } |
|
968 |
2974
|
969 octave_function * |
|
970 octave_value::function_value (bool silent) |
|
971 { |
|
972 return rep->function_value (silent); |
|
973 } |
|
974 |
4700
|
975 octave_user_function * |
|
976 octave_value::user_function_value (bool silent) |
|
977 { |
|
978 return rep->user_function_value (silent); |
|
979 } |
|
980 |
4346
|
981 octave_fcn_handle * |
4343
|
982 octave_value::fcn_handle_value (bool silent) |
|
983 { |
|
984 return rep->fcn_handle_value (silent); |
|
985 } |
|
986 |
4933
|
987 octave_fcn_inline * |
|
988 octave_value::fcn_inline_value (bool silent) |
|
989 { |
|
990 return rep->fcn_inline_value (silent); |
|
991 } |
|
992 |
2880
|
993 octave_value_list |
|
994 octave_value::list_value (void) const |
|
995 { |
|
996 return rep->list_value (); |
|
997 } |
|
998 |
2376
|
999 ColumnVector |
3419
|
1000 octave_value::column_vector_value (bool force_string_conv, |
4661
|
1001 bool /* frc_vec_conv */) const |
3419
|
1002 { |
|
1003 ColumnVector retval; |
|
1004 |
|
1005 Matrix m = matrix_value (force_string_conv); |
|
1006 |
|
1007 if (error_state) |
|
1008 return retval; |
|
1009 |
5275
|
1010 octave_idx_type nr = m.rows (); |
|
1011 octave_idx_type nc = m.columns (); |
3419
|
1012 |
|
1013 if (nc == 1) |
|
1014 { |
|
1015 retval.resize (nr); |
5275
|
1016 for (octave_idx_type i = 0; i < nr; i++) |
3419
|
1017 retval (i) = m (i, 0); |
|
1018 } |
|
1019 else |
|
1020 { |
3523
|
1021 std::string tn = type_name (); |
3419
|
1022 gripe_invalid_conversion (tn.c_str (), "real column vector"); |
|
1023 } |
|
1024 |
|
1025 return retval; |
|
1026 } |
|
1027 |
|
1028 ComplexColumnVector |
|
1029 octave_value::complex_column_vector_value (bool force_string_conv, |
4661
|
1030 bool /* frc_vec_conv */) const |
3419
|
1031 { |
|
1032 ComplexColumnVector retval; |
|
1033 |
|
1034 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1035 |
|
1036 if (error_state) |
|
1037 return retval; |
|
1038 |
5275
|
1039 octave_idx_type nr = m.rows (); |
|
1040 octave_idx_type nc = m.columns (); |
3419
|
1041 |
|
1042 if (nc == 1) |
|
1043 { |
3465
|
1044 retval.resize (nr); |
5275
|
1045 for (octave_idx_type i = 0; i < nr; i++) |
3419
|
1046 retval (i) = m (i, 0); |
|
1047 } |
|
1048 else |
|
1049 { |
3523
|
1050 std::string tn = type_name (); |
3419
|
1051 gripe_invalid_conversion (tn.c_str (), "complex column vector"); |
|
1052 } |
|
1053 |
|
1054 return retval; |
|
1055 } |
|
1056 |
|
1057 RowVector |
|
1058 octave_value::row_vector_value (bool force_string_conv, |
4661
|
1059 bool /* frc_vec_conv */) const |
3419
|
1060 { |
|
1061 RowVector retval; |
|
1062 |
|
1063 Matrix m = matrix_value (force_string_conv); |
|
1064 |
|
1065 if (error_state) |
|
1066 return retval; |
|
1067 |
5275
|
1068 octave_idx_type nr = m.rows (); |
|
1069 octave_idx_type nc = m.columns (); |
3419
|
1070 |
|
1071 if (nr == 1) |
|
1072 { |
|
1073 retval.resize (nc); |
5275
|
1074 for (octave_idx_type i = 0; i < nc; i++) |
3419
|
1075 retval (i) = m (0, i); |
|
1076 } |
|
1077 else |
|
1078 { |
3523
|
1079 std::string tn = type_name (); |
3419
|
1080 gripe_invalid_conversion (tn.c_str (), "real row vector"); |
|
1081 } |
|
1082 |
|
1083 return retval; |
|
1084 } |
|
1085 |
|
1086 ComplexRowVector |
|
1087 octave_value::complex_row_vector_value (bool force_string_conv, |
4661
|
1088 bool /* frc_vec_conv */) const |
3419
|
1089 { |
|
1090 ComplexRowVector retval; |
|
1091 |
|
1092 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1093 |
|
1094 if (error_state) |
|
1095 return retval; |
|
1096 |
5275
|
1097 octave_idx_type nr = m.rows (); |
|
1098 octave_idx_type nc = m.columns (); |
3419
|
1099 |
|
1100 if (nr == 1) |
|
1101 { |
|
1102 retval.resize (nc); |
5275
|
1103 for (octave_idx_type i = 0; i < nc; i++) |
3419
|
1104 retval (i) = m (0, i); |
|
1105 } |
|
1106 else |
|
1107 { |
3523
|
1108 std::string tn = type_name (); |
3419
|
1109 gripe_invalid_conversion (tn.c_str (), "complex row vector"); |
|
1110 } |
|
1111 |
|
1112 return retval; |
|
1113 } |
|
1114 |
|
1115 // Sloppy... |
|
1116 |
|
1117 Array<double> |
2376
|
1118 octave_value::vector_value (bool force_string_conv, |
|
1119 bool force_vector_conversion) const |
|
1120 { |
3419
|
1121 Array<double> retval; |
2376
|
1122 |
|
1123 Matrix m = matrix_value (force_string_conv); |
|
1124 |
|
1125 if (error_state) |
|
1126 return retval; |
|
1127 |
5275
|
1128 octave_idx_type nr = m.rows (); |
|
1129 octave_idx_type nc = m.columns (); |
2376
|
1130 |
|
1131 if (nr == 1) |
|
1132 { |
|
1133 retval.resize (nc); |
5275
|
1134 for (octave_idx_type i = 0; i < nc; i++) |
2376
|
1135 retval (i) = m (0, i); |
|
1136 } |
|
1137 else if (nc == 1) |
|
1138 { |
|
1139 retval.resize (nr); |
5275
|
1140 for (octave_idx_type i = 0; i < nr; i++) |
2376
|
1141 retval (i) = m (i, 0); |
|
1142 } |
4455
|
1143 else if (nr > 0 && nc > 0) |
2376
|
1144 { |
4455
|
1145 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
1146 if (! force_vector_conversion && Vwarn_fortran_indexing) |
|
1147 gripe_implicit_conversion (type_name (), "real vector"); |
|
1148 |
2376
|
1149 retval.resize (nr * nc); |
5275
|
1150 octave_idx_type k = 0; |
|
1151 for (octave_idx_type j = 0; j < nc; j++) |
|
1152 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
1153 { |
|
1154 OCTAVE_QUIT; |
|
1155 |
|
1156 retval (k++) = m (i, j); |
|
1157 } |
2376
|
1158 } |
|
1159 else |
|
1160 { |
3523
|
1161 std::string tn = type_name (); |
2376
|
1162 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
1163 } |
|
1164 |
|
1165 return retval; |
|
1166 } |
|
1167 |
4044
|
1168 Array<int> |
|
1169 octave_value::int_vector_value (bool force_string_conv, bool require_int, |
|
1170 bool force_vector_conversion) const |
|
1171 { |
|
1172 Array<int> retval; |
|
1173 |
|
1174 Matrix m = matrix_value (force_string_conv); |
|
1175 |
|
1176 if (error_state) |
|
1177 return retval; |
|
1178 |
5275
|
1179 octave_idx_type nr = m.rows (); |
|
1180 octave_idx_type nc = m.columns (); |
4044
|
1181 |
|
1182 if (nr == 1) |
|
1183 { |
|
1184 retval.resize (nc); |
5275
|
1185 for (octave_idx_type i = 0; i < nc; i++) |
4044
|
1186 { |
4153
|
1187 OCTAVE_QUIT; |
|
1188 |
4044
|
1189 double d = m (0, i); |
|
1190 |
|
1191 if (require_int && D_NINT (d) != d) |
|
1192 { |
|
1193 error ("conversion to integer value failed"); |
|
1194 return retval; |
|
1195 } |
|
1196 |
|
1197 retval (i) = static_cast<int> (d); |
|
1198 } |
|
1199 } |
|
1200 else if (nc == 1) |
|
1201 { |
|
1202 retval.resize (nr); |
5275
|
1203 for (octave_idx_type i = 0; i < nr; i++) |
4044
|
1204 { |
4153
|
1205 OCTAVE_QUIT; |
|
1206 |
4044
|
1207 double d = m (i, 0); |
|
1208 |
|
1209 if (require_int && D_NINT (d) != d) |
|
1210 { |
|
1211 error ("conversion to integer value failed"); |
|
1212 return retval; |
|
1213 } |
|
1214 |
|
1215 retval (i) = static_cast<int> (d); |
|
1216 } |
|
1217 } |
4455
|
1218 else if (nr > 0 && nc > 0) |
4044
|
1219 { |
4455
|
1220 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
1221 if (! force_vector_conversion && Vwarn_fortran_indexing) |
|
1222 gripe_implicit_conversion (type_name (), "real vector"); |
|
1223 |
4044
|
1224 retval.resize (nr * nc); |
5275
|
1225 octave_idx_type k = 0; |
|
1226 for (octave_idx_type j = 0; j < nc; j++) |
4044
|
1227 { |
5275
|
1228 for (octave_idx_type i = 0; i < nr; i++) |
4044
|
1229 { |
4153
|
1230 OCTAVE_QUIT; |
|
1231 |
4044
|
1232 double d = m (i, j); |
|
1233 |
|
1234 if (require_int && D_NINT (d) != d) |
|
1235 { |
|
1236 error ("conversion to integer value failed"); |
|
1237 return retval; |
|
1238 } |
|
1239 |
|
1240 retval (k++) = static_cast<int> (d); |
|
1241 } |
|
1242 } |
|
1243 } |
|
1244 else |
|
1245 { |
|
1246 std::string tn = type_name (); |
|
1247 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
1248 } |
|
1249 |
|
1250 return retval; |
|
1251 } |
|
1252 |
3419
|
1253 Array<Complex> |
2376
|
1254 octave_value::complex_vector_value (bool force_string_conv, |
|
1255 bool force_vector_conversion) const |
|
1256 { |
3419
|
1257 Array<Complex> retval; |
2376
|
1258 |
|
1259 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1260 |
|
1261 if (error_state) |
|
1262 return retval; |
|
1263 |
5275
|
1264 octave_idx_type nr = m.rows (); |
|
1265 octave_idx_type nc = m.columns (); |
2376
|
1266 |
|
1267 if (nr == 1) |
|
1268 { |
|
1269 retval.resize (nc); |
5275
|
1270 for (octave_idx_type i = 0; i < nc; i++) |
4153
|
1271 { |
|
1272 OCTAVE_QUIT; |
|
1273 retval (i) = m (0, i); |
|
1274 } |
2376
|
1275 } |
|
1276 else if (nc == 1) |
|
1277 { |
|
1278 retval.resize (nr); |
5275
|
1279 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
1280 { |
|
1281 OCTAVE_QUIT; |
|
1282 retval (i) = m (i, 0); |
|
1283 } |
2376
|
1284 } |
4455
|
1285 else if (nr > 0 && nc > 0) |
2376
|
1286 { |
4455
|
1287 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
1288 if (! force_vector_conversion && Vwarn_fortran_indexing) |
|
1289 gripe_implicit_conversion (type_name (), "complex vector"); |
|
1290 |
2376
|
1291 retval.resize (nr * nc); |
5275
|
1292 octave_idx_type k = 0; |
|
1293 for (octave_idx_type j = 0; j < nc; j++) |
|
1294 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
1295 { |
|
1296 OCTAVE_QUIT; |
|
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 (), "complex vector"); |
|
1304 } |
|
1305 |
|
1306 return retval; |
|
1307 } |
|
1308 |
4944
|
1309 int |
|
1310 octave_value::write (octave_stream& os, int block_size, |
|
1311 oct_data_conv::data_type output_type, int skip, |
|
1312 oct_mach_info::float_format flt_fmt) const |
|
1313 { |
|
1314 return rep->write (os, block_size, output_type, skip, flt_fmt); |
|
1315 } |
|
1316 |
2413
|
1317 static void |
3933
|
1318 gripe_binary_op (const std::string& on, const std::string& tn1, |
|
1319 const std::string& tn2) |
2376
|
1320 { |
2903
|
1321 error ("binary operator `%s' not implemented for `%s' by `%s' operations", |
2376
|
1322 on.c_str (), tn1.c_str (), tn2.c_str ()); |
|
1323 } |
|
1324 |
3203
|
1325 static void |
3523
|
1326 gripe_binary_op_conv (const std::string& on) |
3203
|
1327 { |
|
1328 error ("type conversion failed for binary operator `%s'", on.c_str ()); |
|
1329 } |
|
1330 |
2376
|
1331 octave_value |
3933
|
1332 do_binary_op (octave_value::binary_op op, |
|
1333 const octave_value& v1, const octave_value& v2) |
2376
|
1334 { |
|
1335 octave_value retval; |
|
1336 |
|
1337 int t1 = v1.type_id (); |
|
1338 int t2 = v2.type_id (); |
|
1339 |
5759
|
1340 octave_value_typeinfo::binary_op_fcn f |
|
1341 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1342 |
|
1343 if (f) |
|
1344 retval = f (*v1.rep, *v2.rep); |
|
1345 else |
|
1346 { |
|
1347 octave_value tv1; |
5759
|
1348 octave_base_value::type_conv_fcn cf1 = v1.numeric_conversion_function (); |
2376
|
1349 |
|
1350 if (cf1) |
|
1351 { |
5759
|
1352 octave_base_value *tmp = cf1 (*v1.rep); |
3203
|
1353 |
|
1354 if (tmp) |
|
1355 { |
|
1356 tv1 = octave_value (tmp); |
|
1357 t1 = tv1.type_id (); |
|
1358 } |
|
1359 else |
|
1360 { |
|
1361 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1362 return retval; |
|
1363 } |
2376
|
1364 } |
|
1365 else |
|
1366 tv1 = v1; |
|
1367 |
|
1368 octave_value tv2; |
5759
|
1369 octave_base_value::type_conv_fcn cf2 = v2.numeric_conversion_function (); |
2376
|
1370 |
|
1371 if (cf2) |
|
1372 { |
5759
|
1373 octave_base_value *tmp = cf2 (*v2.rep); |
3203
|
1374 |
|
1375 if (tmp) |
|
1376 { |
|
1377 tv2 = octave_value (tmp); |
|
1378 t2 = tv2.type_id (); |
|
1379 } |
|
1380 else |
|
1381 { |
|
1382 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1383 return retval; |
|
1384 } |
2376
|
1385 } |
|
1386 else |
|
1387 tv2 = v2; |
|
1388 |
|
1389 if (cf1 || cf2) |
|
1390 { |
4587
|
1391 f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1392 |
|
1393 if (f) |
|
1394 retval = f (*tv1.rep, *tv2.rep); |
|
1395 else |
|
1396 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1397 v1.type_name (), v2.type_name ()); |
|
1398 } |
|
1399 else |
|
1400 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1401 v1.type_name (), v2.type_name ()); |
|
1402 } |
|
1403 |
|
1404 return retval; |
|
1405 } |
|
1406 |
4915
|
1407 static void |
|
1408 gripe_cat_op (const std::string& tn1, const std::string& tn2) |
|
1409 { |
|
1410 error ("concatenation operator not implemented for `%s' by `%s' operations", |
|
1411 tn1.c_str (), tn2.c_str ()); |
|
1412 } |
|
1413 |
|
1414 static void |
|
1415 gripe_cat_op_conv (void) |
|
1416 { |
|
1417 error ("type conversion failed for concatenation operator"); |
|
1418 } |
|
1419 |
|
1420 octave_value |
|
1421 do_cat_op (const octave_value& v1, const octave_value& v2, |
|
1422 const Array<int>& ra_idx) |
|
1423 { |
|
1424 octave_value retval; |
|
1425 |
5164
|
1426 // Rapid return for concatenation with an empty object. Dimension |
|
1427 // checking handled elsewhere. |
|
1428 if (v1.all_zero_dims ()) |
|
1429 return v2; |
|
1430 if (v2.all_zero_dims ()) |
|
1431 return v1; |
|
1432 |
4915
|
1433 int t1 = v1.type_id (); |
|
1434 int t2 = v2.type_id (); |
|
1435 |
5759
|
1436 octave_value_typeinfo::cat_op_fcn f |
|
1437 = octave_value_typeinfo::lookup_cat_op (t1, t2); |
4915
|
1438 |
|
1439 if (f) |
|
1440 retval = f (*v1.rep, *v2.rep, ra_idx); |
|
1441 else |
|
1442 { |
|
1443 octave_value tv1; |
5759
|
1444 octave_base_value::type_conv_fcn cf1 = v1.numeric_conversion_function (); |
4915
|
1445 |
|
1446 if (cf1) |
|
1447 { |
5759
|
1448 octave_base_value *tmp = cf1 (*v1.rep); |
4915
|
1449 |
|
1450 if (tmp) |
|
1451 { |
|
1452 tv1 = octave_value (tmp); |
|
1453 t1 = tv1.type_id (); |
|
1454 } |
|
1455 else |
|
1456 { |
|
1457 gripe_cat_op_conv (); |
|
1458 return retval; |
|
1459 } |
|
1460 } |
|
1461 else |
|
1462 tv1 = v1; |
|
1463 |
|
1464 octave_value tv2; |
5759
|
1465 octave_base_value::type_conv_fcn cf2 = v2.numeric_conversion_function (); |
4915
|
1466 |
|
1467 if (cf2) |
|
1468 { |
5759
|
1469 octave_base_value *tmp = cf2 (*v2.rep); |
4915
|
1470 |
|
1471 if (tmp) |
|
1472 { |
|
1473 tv2 = octave_value (tmp); |
|
1474 t2 = tv2.type_id (); |
|
1475 } |
|
1476 else |
|
1477 { |
|
1478 gripe_cat_op_conv (); |
|
1479 return retval; |
|
1480 } |
|
1481 } |
|
1482 else |
|
1483 tv2 = v2; |
|
1484 |
|
1485 if (cf1 || cf2) |
|
1486 { |
|
1487 f = octave_value_typeinfo::lookup_cat_op (t1, t2); |
|
1488 |
|
1489 if (f) |
|
1490 retval = f (*tv1.rep, *tv2.rep, ra_idx); |
|
1491 else |
|
1492 gripe_cat_op (v1.type_name (), v2.type_name ()); |
|
1493 } |
|
1494 else |
|
1495 gripe_cat_op (v1.type_name (), v2.type_name ()); |
|
1496 } |
|
1497 |
|
1498 return retval; |
|
1499 } |
|
1500 |
3933
|
1501 void |
|
1502 octave_value::print_info (std::ostream& os, const std::string& prefix) const |
|
1503 { |
|
1504 os << prefix << "type_name: " << type_name () << "\n" |
|
1505 << prefix << "count: " << get_count () << "\n" |
|
1506 << prefix << "rep info: "; |
|
1507 |
|
1508 rep->print_info (os, prefix + " "); |
|
1509 } |
|
1510 |
3203
|
1511 static void |
3523
|
1512 gripe_unary_op (const std::string& on, const std::string& tn) |
3203
|
1513 { |
|
1514 error ("unary operator `%s' not implemented for `%s' operands", |
|
1515 on.c_str (), tn.c_str ()); |
|
1516 } |
|
1517 |
|
1518 static void |
3523
|
1519 gripe_unary_op_conv (const std::string& on) |
3203
|
1520 { |
|
1521 error ("type conversion failed for unary operator `%s'", on.c_str ()); |
|
1522 } |
|
1523 |
|
1524 octave_value |
|
1525 do_unary_op (octave_value::unary_op op, const octave_value& v) |
|
1526 { |
|
1527 octave_value retval; |
|
1528 |
|
1529 int t = v.type_id (); |
|
1530 |
5759
|
1531 octave_value_typeinfo::unary_op_fcn f |
|
1532 = octave_value_typeinfo::lookup_unary_op (op, t); |
3203
|
1533 |
|
1534 if (f) |
|
1535 retval = f (*v.rep); |
|
1536 else |
|
1537 { |
|
1538 octave_value tv; |
5759
|
1539 octave_base_value::type_conv_fcn cf = v.numeric_conversion_function (); |
3203
|
1540 |
|
1541 if (cf) |
|
1542 { |
5759
|
1543 octave_base_value *tmp = cf (*v.rep); |
3203
|
1544 |
|
1545 if (tmp) |
|
1546 { |
|
1547 tv = octave_value (tmp); |
|
1548 t = tv.type_id (); |
|
1549 |
4587
|
1550 f = octave_value_typeinfo::lookup_unary_op (op, t); |
3203
|
1551 |
|
1552 if (f) |
|
1553 retval = f (*tv.rep); |
|
1554 else |
|
1555 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1556 v.type_name ()); |
|
1557 } |
|
1558 else |
|
1559 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
|
1560 } |
|
1561 else |
|
1562 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1563 v.type_name ()); |
|
1564 } |
|
1565 |
|
1566 return retval; |
|
1567 } |
|
1568 |
|
1569 static void |
3933
|
1570 gripe_unary_op_conversion_failed (const std::string& op, |
|
1571 const std::string& tn) |
3203
|
1572 { |
|
1573 error ("operator %s: type conversion for `%s' failed", |
|
1574 op.c_str (), tn.c_str ()); |
|
1575 } |
|
1576 |
3933
|
1577 const octave_value& |
|
1578 octave_value::do_non_const_unary_op (unary_op op) |
3203
|
1579 { |
|
1580 octave_value retval; |
|
1581 |
|
1582 int t = type_id (); |
|
1583 |
5759
|
1584 octave_value_typeinfo::non_const_unary_op_fcn f |
3203
|
1585 = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1586 |
|
1587 if (f) |
|
1588 { |
|
1589 make_unique (); |
|
1590 |
|
1591 f (*rep); |
|
1592 } |
|
1593 else |
|
1594 { |
5759
|
1595 octave_base_value::type_conv_fcn cf = numeric_conversion_function (); |
3203
|
1596 |
|
1597 if (cf) |
|
1598 { |
5759
|
1599 octave_base_value *tmp = cf (*rep); |
3203
|
1600 |
|
1601 if (tmp) |
|
1602 { |
5759
|
1603 octave_base_value *old_rep = rep; |
3203
|
1604 rep = tmp; |
|
1605 |
|
1606 t = type_id (); |
|
1607 |
|
1608 f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1609 |
|
1610 if (f) |
|
1611 { |
|
1612 f (*rep); |
|
1613 |
|
1614 if (old_rep && --old_rep->count == 0) |
|
1615 delete old_rep; |
|
1616 } |
|
1617 else |
|
1618 { |
|
1619 if (old_rep) |
|
1620 { |
|
1621 if (--rep->count == 0) |
|
1622 delete rep; |
|
1623 |
|
1624 rep = old_rep; |
|
1625 } |
|
1626 |
|
1627 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1628 type_name ()); |
|
1629 } |
|
1630 } |
|
1631 else |
|
1632 gripe_unary_op_conversion_failed |
|
1633 (octave_value::unary_op_as_string (op), type_name ()); |
|
1634 } |
|
1635 else |
|
1636 gripe_unary_op (octave_value::unary_op_as_string (op), type_name ()); |
|
1637 } |
3933
|
1638 |
|
1639 return *this; |
3203
|
1640 } |
|
1641 |
3933
|
1642 #if 0 |
3205
|
1643 static void |
3933
|
1644 gripe_unary_op_failed_or_no_method (const std::string& on, |
|
1645 const std::string& tn) |
3205
|
1646 { |
|
1647 error ("operator %s: no method, or unable to evaluate for %s operand", |
|
1648 on.c_str (), tn.c_str ()); |
|
1649 } |
3933
|
1650 #endif |
3205
|
1651 |
|
1652 void |
4661
|
1653 octave_value::do_non_const_unary_op (unary_op, const octave_value_list&) |
3205
|
1654 { |
3933
|
1655 abort (); |
|
1656 } |
|
1657 |
|
1658 octave_value |
4247
|
1659 octave_value::do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
1660 const std::list<octave_value_list>& idx) |
3933
|
1661 { |
|
1662 octave_value retval; |
|
1663 |
|
1664 if (idx.empty ()) |
|
1665 { |
|
1666 do_non_const_unary_op (op); |
3205
|
1667 |
3933
|
1668 retval = *this; |
|
1669 } |
|
1670 else |
|
1671 { |
|
1672 // XXX FIXME XXX -- only do the following stuff if we can't find a |
|
1673 // specific function to call to handle the op= operation for the |
|
1674 // types we have. |
3205
|
1675 |
3933
|
1676 assign_op assop = unary_op_to_assign_op (op); |
|
1677 |
|
1678 retval = assign (assop, type, idx, 1.0); |
|
1679 } |
|
1680 |
|
1681 return retval; |
3205
|
1682 } |
|
1683 |
|
1684 octave_value::assign_op |
|
1685 octave_value::unary_op_to_assign_op (unary_op op) |
|
1686 { |
|
1687 assign_op binop = unknown_assign_op; |
|
1688 |
|
1689 switch (op) |
|
1690 { |
3533
|
1691 case op_incr: |
|
1692 binop = op_add_eq; |
3205
|
1693 break; |
|
1694 |
3533
|
1695 case op_decr: |
|
1696 binop = op_sub_eq; |
3205
|
1697 break; |
|
1698 |
|
1699 default: |
|
1700 { |
3523
|
1701 std::string on = unary_op_as_string (op); |
3205
|
1702 error ("operator %s: no assign operator found", on.c_str ()); |
|
1703 } |
|
1704 } |
|
1705 |
|
1706 return binop; |
|
1707 } |
|
1708 |
3204
|
1709 octave_value::binary_op |
|
1710 octave_value::op_eq_to_binary_op (assign_op op) |
|
1711 { |
|
1712 binary_op binop = unknown_binary_op; |
|
1713 |
|
1714 switch (op) |
|
1715 { |
3533
|
1716 case op_add_eq: |
|
1717 binop = op_add; |
3204
|
1718 break; |
|
1719 |
3533
|
1720 case op_sub_eq: |
|
1721 binop = op_sub; |
3204
|
1722 break; |
|
1723 |
3533
|
1724 case op_mul_eq: |
|
1725 binop = op_mul; |
3204
|
1726 break; |
|
1727 |
3533
|
1728 case op_div_eq: |
|
1729 binop = op_div; |
3204
|
1730 break; |
|
1731 |
3533
|
1732 case op_ldiv_eq: |
|
1733 binop = op_ldiv; |
3204
|
1734 break; |
|
1735 |
4018
|
1736 case op_pow_eq: |
|
1737 binop = op_pow; |
|
1738 break; |
|
1739 |
3533
|
1740 case op_lshift_eq: |
|
1741 binop = op_lshift; |
3204
|
1742 break; |
|
1743 |
3533
|
1744 case op_rshift_eq: |
|
1745 binop = op_rshift; |
3204
|
1746 break; |
|
1747 |
3533
|
1748 case op_el_mul_eq: |
|
1749 binop = op_el_mul; |
3204
|
1750 break; |
|
1751 |
3533
|
1752 case op_el_div_eq: |
|
1753 binop = op_el_div; |
3204
|
1754 break; |
|
1755 |
3533
|
1756 case op_el_ldiv_eq: |
|
1757 binop = op_el_ldiv; |
3204
|
1758 break; |
|
1759 |
4018
|
1760 case op_el_pow_eq: |
|
1761 binop = op_el_pow; |
|
1762 break; |
|
1763 |
3533
|
1764 case op_el_and_eq: |
|
1765 binop = op_el_and; |
3204
|
1766 break; |
|
1767 |
3533
|
1768 case op_el_or_eq: |
|
1769 binop = op_el_or; |
3204
|
1770 break; |
|
1771 |
|
1772 default: |
|
1773 { |
3523
|
1774 std::string on = assign_op_as_string (op); |
3204
|
1775 error ("operator %s: no binary operator found", on.c_str ()); |
|
1776 } |
|
1777 } |
|
1778 |
|
1779 return binop; |
|
1780 } |
|
1781 |
3933
|
1782 octave_value |
|
1783 octave_value::empty_conv (const std::string& type, const octave_value& rhs) |
|
1784 { |
|
1785 octave_value retval; |
|
1786 |
|
1787 if (type.length () > 0) |
|
1788 { |
|
1789 switch (type[0]) |
|
1790 { |
|
1791 case '(': |
|
1792 { |
|
1793 if (type.length () > 1 && type[1] == '.') |
|
1794 retval = Octave_map (); |
|
1795 else |
|
1796 retval = octave_value (rhs.empty_clone ()); |
|
1797 } |
|
1798 break; |
|
1799 |
|
1800 case '{': |
|
1801 retval = Cell (); |
|
1802 break; |
|
1803 |
|
1804 case '.': |
|
1805 retval = Octave_map (); |
|
1806 break; |
|
1807 |
|
1808 default: |
|
1809 panic_impossible (); |
|
1810 } |
|
1811 } |
|
1812 else |
|
1813 retval = octave_value (rhs.empty_clone ()); |
|
1814 |
|
1815 return retval; |
|
1816 } |
|
1817 |
2376
|
1818 void |
|
1819 install_types (void) |
|
1820 { |
|
1821 octave_base_value::register_type (); |
3928
|
1822 octave_cell::register_type (); |
2376
|
1823 octave_scalar::register_type (); |
|
1824 octave_complex::register_type (); |
|
1825 octave_matrix::register_type (); |
|
1826 octave_complex_matrix::register_type (); |
|
1827 octave_range::register_type (); |
2825
|
1828 octave_bool::register_type (); |
|
1829 octave_bool_matrix::register_type (); |
2376
|
1830 octave_char_matrix::register_type (); |
|
1831 octave_char_matrix_str::register_type (); |
5279
|
1832 octave_char_matrix_sq_str::register_type (); |
4901
|
1833 octave_int8_scalar::register_type (); |
|
1834 octave_int16_scalar::register_type (); |
|
1835 octave_int32_scalar::register_type (); |
|
1836 octave_int64_scalar::register_type (); |
|
1837 octave_uint8_scalar::register_type (); |
|
1838 octave_uint16_scalar::register_type (); |
|
1839 octave_uint32_scalar::register_type (); |
|
1840 octave_uint64_scalar::register_type (); |
|
1841 octave_int8_matrix::register_type (); |
|
1842 octave_int16_matrix::register_type (); |
|
1843 octave_int32_matrix::register_type (); |
|
1844 octave_int64_matrix::register_type (); |
|
1845 octave_uint8_matrix::register_type (); |
|
1846 octave_uint16_matrix::register_type (); |
|
1847 octave_uint32_matrix::register_type (); |
|
1848 octave_uint64_matrix::register_type (); |
5164
|
1849 octave_sparse_bool_matrix::register_type (); |
|
1850 octave_sparse_matrix::register_type (); |
|
1851 octave_sparse_complex_matrix::register_type (); |
2376
|
1852 octave_struct::register_type (); |
2880
|
1853 octave_list::register_type (); |
3977
|
1854 octave_cs_list::register_type (); |
2376
|
1855 octave_all_va_args::register_type (); |
|
1856 octave_magic_colon::register_type (); |
2974
|
1857 octave_builtin::register_type (); |
|
1858 octave_mapper::register_type (); |
|
1859 octave_user_function::register_type (); |
4649
|
1860 octave_dld_function::register_type (); |
4643
|
1861 octave_fcn_handle::register_type (); |
4966
|
1862 octave_fcn_inline::register_type (); |
4643
|
1863 octave_streamoff::register_type (); |
2376
|
1864 } |
|
1865 |
4970
|
1866 #if 0 |
|
1867 DEFUN (cast, args, , |
|
1868 "-*- texinfo -*-\n\ |
|
1869 @deftypefn {Built-in Function} {} cast (@var{val}, @var{type})\n\ |
|
1870 Convert @var{val} to the new data type @var{type}.\n\ |
5642
|
1871 @seealso{class, typeinfo}\n\ |
|
1872 @end deftypefn") |
4970
|
1873 { |
|
1874 octave_value retval; |
|
1875 |
|
1876 if (args.length () == 2) |
|
1877 error ("cast: not implemented"); |
|
1878 else |
|
1879 print_usage ("cast"); |
|
1880 |
|
1881 return retval; |
|
1882 } |
|
1883 #endif |
|
1884 |
4791
|
1885 DEFUN (sizeof, args, , |
|
1886 "-*- texinfo -*-\n\ |
|
1887 @deftypefn {Built-in Function} {} sizeof (@var{val})\n\ |
|
1888 Return the size of @var{val} in bytes\n\ |
|
1889 @end deftypefn") |
|
1890 { |
|
1891 octave_value retval; |
|
1892 |
|
1893 if (args.length () == 1) |
|
1894 retval = args(0).byte_size (); |
|
1895 else |
|
1896 print_usage ("sizeof"); |
|
1897 |
|
1898 return retval; |
|
1899 } |
|
1900 |
2376
|
1901 static int |
4455
|
1902 warn_fortran_indexing (void) |
2376
|
1903 { |
4455
|
1904 Vwarn_fortran_indexing = check_preference ("warn_fortran_indexing"); |
2376
|
1905 |
4455
|
1906 liboctave_wfi_flag = Vwarn_fortran_indexing; |
2376
|
1907 |
|
1908 return 0; |
|
1909 } |
|
1910 |
|
1911 static int |
4452
|
1912 warn_imag_to_real (void) |
4257
|
1913 { |
4452
|
1914 Vwarn_imag_to_real = check_preference ("warn_imag_to_real"); |
4257
|
1915 |
|
1916 return 0; |
|
1917 } |
|
1918 |
2376
|
1919 void |
2909
|
1920 symbols_of_ov (void) |
2376
|
1921 { |
4455
|
1922 DEFVAR (warn_fortran_indexing, false, warn_fortran_indexing, |
|
1923 "-*- texinfo -*-\n\ |
|
1924 @defvr {Built-in Variable} warn_fortran_indexing\n\ |
|
1925 If the value of @code{warn_fortran_indexing} is nonzero, a warning is\n\ |
|
1926 printed for expressions which select elements of a two-dimensional matrix\n\ |
|
1927 using a single index. The default value is 0.\n\ |
|
1928 @end defvr"); |
|
1929 |
4451
|
1930 DEFVAR (warn_imag_to_real, false, warn_imag_to_real, |
|
1931 "-*- texinfo -*-\n\ |
|
1932 @defvr {Built-in Variable} warn_imag_to_real\n\ |
|
1933 If the value of @code{warn_imag_to_real} is nonzero, a warning is\n\ |
|
1934 printed for implicit conversions of complex numbers to real numbers.\n\ |
|
1935 The default value is 0.\n\ |
|
1936 @end defvr"); |
2376
|
1937 } |
|
1938 |
|
1939 /* |
|
1940 ;;; Local Variables: *** |
|
1941 ;;; mode: C++ *** |
|
1942 ;;; End: *** |
|
1943 */ |