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