2376
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
|
4 2006, 2007 John W. Eaton |
2376
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2376
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
2376
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
4254
|
28 #include <climits> |
|
29 |
3503
|
30 #include <iostream> |
2901
|
31 |
2376
|
32 #include "lo-ieee.h" |
4732
|
33 #include "lo-mappers.h" |
4649
|
34 #include "so-array.h" |
2376
|
35 |
5759
|
36 #include "defun.h" |
2376
|
37 #include "gripes.h" |
|
38 #include "oct-map.h" |
2974
|
39 #include "oct-obj.h" |
2979
|
40 #include "oct-lvalue.h" |
3340
|
41 #include "oct-stream.h" |
2376
|
42 #include "ops.h" |
|
43 #include "ov-base.h" |
3928
|
44 #include "ov-cell.h" |
|
45 #include "ov-ch-mat.h" |
2376
|
46 #include "ov-complex.h" |
|
47 #include "ov-cx-mat.h" |
3928
|
48 #include "ov-list.h" |
|
49 #include "ov-range.h" |
|
50 #include "ov-re-mat.h" |
|
51 #include "ov-scalar.h" |
2376
|
52 #include "ov-str-mat.h" |
4343
|
53 #include "ov-fcn-handle.h" |
5759
|
54 #include "parse.h" |
|
55 #include "utils.h" |
2948
|
56 #include "variables.h" |
2376
|
57 |
4612
|
58 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_base_value, |
|
59 "<unknown type>", "unknown"); |
2376
|
60 |
5759
|
61 // If TRUE, print the name along with the value. |
5794
|
62 static bool Vprint_answer_id_name = true; |
5759
|
63 |
|
64 // If TRUE, turn off printing of results in functions (as if a |
|
65 // semicolon has been appended to each statement). |
5794
|
66 static bool Vsilent_functions = false; |
5759
|
67 |
7193
|
68 // TRUE means to perform automatic sparse to real mutation if there |
|
69 // is memory to be saved |
|
70 bool Vsparse_auto_mutate = false; |
|
71 |
2376
|
72 octave_value |
4532
|
73 octave_base_value::squeeze (void) const |
|
74 { |
|
75 std::string nm = type_name (); |
|
76 error ("squeeze: invalid operation for %s type", nm.c_str ()); |
|
77 return octave_value (); |
|
78 } |
|
79 |
|
80 octave_value |
4247
|
81 octave_base_value::subsref (const std::string&, |
4219
|
82 const std::list<octave_value_list>&) |
3933
|
83 { |
|
84 std::string nm = type_name (); |
|
85 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
86 return octave_value (); |
|
87 } |
|
88 |
|
89 octave_value_list |
4247
|
90 octave_base_value::subsref (const std::string&, |
4219
|
91 const std::list<octave_value_list>&, int) |
3933
|
92 { |
|
93 std::string nm = type_name (); |
|
94 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
95 return octave_value (); |
|
96 } |
|
97 |
|
98 octave_value |
5885
|
99 octave_base_value::do_index_op (const octave_value_list&, bool) |
2974
|
100 { |
3523
|
101 std::string nm = type_name (); |
2974
|
102 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
103 return octave_value (); |
|
104 } |
|
105 |
|
106 octave_value_list |
3544
|
107 octave_base_value::do_multi_index_op (int, const octave_value_list&) |
2376
|
108 { |
3523
|
109 std::string nm = type_name (); |
2376
|
110 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
111 return octave_value (); |
|
112 } |
|
113 |
|
114 idx_vector |
|
115 octave_base_value::index_vector (void) const |
|
116 { |
3523
|
117 std::string nm = type_name (); |
2376
|
118 error ("%s type invalid as index value", nm.c_str ()); |
|
119 return idx_vector (); |
|
120 } |
|
121 |
5759
|
122 int |
|
123 octave_base_value::ndims (void) const |
|
124 { |
|
125 dim_vector dv = dims (); |
|
126 |
|
127 int n_dims = dv.length (); |
|
128 |
|
129 // Remove trailing singleton dimensions. |
|
130 |
|
131 for (int i = n_dims; i > 2; i--) |
|
132 { |
|
133 if (dv(i-1) == 1) |
|
134 n_dims--; |
|
135 else |
|
136 break; |
|
137 } |
|
138 |
|
139 // The result is always >= 2. |
|
140 |
|
141 if (n_dims < 2) |
|
142 n_dims = 2; |
|
143 |
|
144 return n_dims; |
|
145 } |
|
146 |
2376
|
147 octave_value |
4247
|
148 octave_base_value::subsasgn (const std::string& type, |
4219
|
149 const std::list<octave_value_list>& idx, |
3933
|
150 const octave_value& rhs) |
2376
|
151 { |
3933
|
152 octave_value retval; |
2376
|
153 |
3933
|
154 if (is_defined ()) |
|
155 { |
4139
|
156 if (is_numeric_type ()) |
|
157 { |
|
158 switch (type[0]) |
|
159 { |
|
160 case '(': |
|
161 { |
|
162 if (type.length () == 1) |
|
163 retval = numeric_assign (type, idx, rhs); |
4436
|
164 else if (is_empty ()) |
|
165 { |
|
166 // Allow conversion of empty matrix to some other |
|
167 // type in cases like |
|
168 // |
|
169 // x = []; x(i).f = rhs |
|
170 |
|
171 octave_value tmp = octave_value::empty_conv (type, rhs); |
|
172 |
|
173 retval = tmp.subsasgn (type, idx, rhs); |
|
174 } |
4139
|
175 else |
|
176 { |
|
177 std::string nm = type_name (); |
|
178 error ("in indexed assignment of %s, last rhs index must be ()", |
|
179 nm.c_str ()); |
|
180 } |
|
181 } |
|
182 break; |
|
183 |
|
184 case '{': |
|
185 case '.': |
|
186 { |
|
187 std::string nm = type_name (); |
|
188 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
189 } |
|
190 break; |
|
191 |
|
192 default: |
|
193 panic_impossible (); |
|
194 } |
|
195 } |
|
196 else |
|
197 { |
|
198 std::string nm = type_name (); |
|
199 error ("can't perform indexed assignment for %s type", nm.c_str ()); |
|
200 } |
3933
|
201 } |
|
202 else |
|
203 { |
|
204 // Create new object of appropriate type for given index and rhs |
|
205 // types and then call subsasgn again for that object. |
|
206 |
|
207 octave_value tmp = octave_value::empty_conv (type, rhs); |
|
208 |
|
209 retval = tmp.subsasgn (type, idx, rhs); |
|
210 } |
|
211 |
|
212 return retval; |
2376
|
213 } |
|
214 |
5602
|
215 octave_idx_type |
|
216 octave_base_value::nnz (void) const |
|
217 { |
|
218 gripe_wrong_type_arg ("octave_base_value::nnz ()", type_name ()); |
|
219 return -1; |
|
220 } |
|
221 |
5604
|
222 octave_idx_type |
|
223 octave_base_value::nzmax (void) const |
|
224 { |
|
225 gripe_wrong_type_arg ("octave_base_value::nzmax ()", type_name ()); |
|
226 return -1; |
|
227 } |
|
228 |
5900
|
229 octave_idx_type |
|
230 octave_base_value::nfields (void) const |
|
231 { |
|
232 gripe_wrong_type_arg ("octave_base_value::nfields ()", type_name ()); |
|
233 return -1; |
|
234 } |
|
235 |
2376
|
236 octave_value |
4567
|
237 octave_base_value::reshape (const dim_vector&) const |
|
238 { |
|
239 gripe_wrong_type_arg ("octave_base_value::reshape ()", type_name ()); |
|
240 return octave_value (); |
|
241 } |
|
242 |
|
243 octave_value |
4593
|
244 octave_base_value::permute (const Array<int>&, bool) const |
|
245 { |
|
246 gripe_wrong_type_arg ("octave_base_value::permute ()", type_name ()); |
|
247 return octave_value (); |
|
248 } |
|
249 |
|
250 octave_value |
5731
|
251 octave_base_value::resize (const dim_vector&, bool) const |
4915
|
252 { |
|
253 gripe_wrong_type_arg ("octave_base_value::resize ()", type_name ()); |
|
254 return octave_value (); |
|
255 } |
|
256 |
5785
|
257 MatrixType |
|
258 octave_base_value::matrix_type (void) const |
|
259 { |
|
260 gripe_wrong_type_arg ("octave_base_value::matrix_type ()", type_name ()); |
|
261 return MatrixType (); |
|
262 } |
|
263 |
|
264 MatrixType |
|
265 octave_base_value::matrix_type (const MatrixType&) const |
|
266 { |
|
267 gripe_wrong_type_arg ("octave_base_value::matrix_type ()", type_name ()); |
|
268 return MatrixType (); |
|
269 } |
|
270 |
4915
|
271 octave_value |
5759
|
272 octave_base_value::all (int) const |
|
273 { |
|
274 return 0.0; |
|
275 } |
|
276 |
|
277 octave_value |
|
278 octave_base_value::any (int) const |
|
279 { |
|
280 return 0.0; |
|
281 } |
|
282 |
|
283 octave_value |
|
284 octave_base_value::convert_to_str (bool pad, bool force, char type) const |
|
285 { |
|
286 octave_value retval = convert_to_str_internal (pad, force, type); |
|
287 |
5781
|
288 if (! force && is_numeric_type ()) |
|
289 gripe_implicit_conversion ("Octave:num-to-str", |
|
290 type_name (), retval.type_name ()); |
5759
|
291 |
|
292 return retval; |
|
293 } |
|
294 |
|
295 octave_value |
5279
|
296 octave_base_value::convert_to_str_internal (bool, bool, char) const |
2376
|
297 { |
4452
|
298 gripe_wrong_type_arg ("octave_base_value::convert_to_str_internal ()", |
2376
|
299 type_name ()); |
|
300 return octave_value (); |
|
301 } |
|
302 |
|
303 void |
|
304 octave_base_value::convert_to_row_or_column_vector (void) |
|
305 { |
|
306 gripe_wrong_type_arg |
|
307 ("octave_base_value::convert_to_row_or_column_vector ()", |
|
308 type_name ()); |
|
309 } |
|
310 |
|
311 void |
3523
|
312 octave_base_value::print (std::ostream&, bool) const |
2376
|
313 { |
3195
|
314 gripe_wrong_type_arg ("octave_base_value::print ()", type_name ()); |
2376
|
315 } |
|
316 |
2901
|
317 void |
3523
|
318 octave_base_value::print_raw (std::ostream&, bool) const |
2901
|
319 { |
3195
|
320 gripe_wrong_type_arg ("octave_base_value::print_raw ()", type_name ()); |
2901
|
321 } |
|
322 |
|
323 bool |
3523
|
324 octave_base_value::print_name_tag (std::ostream& os, const std::string& name) const |
2901
|
325 { |
4604
|
326 bool retval = false; |
|
327 |
2901
|
328 indent (os); |
4604
|
329 |
|
330 if (print_as_scalar ()) |
|
331 os << name << " = "; |
|
332 else |
|
333 { |
|
334 os << name << " ="; |
|
335 newline (os); |
|
336 newline (os); |
|
337 retval = true; |
|
338 } |
|
339 |
|
340 return retval; |
2901
|
341 } |
|
342 |
3933
|
343 void |
5759
|
344 octave_base_value::print_with_name (std::ostream& output_buf, |
|
345 const std::string& name, |
|
346 bool print_padding) const |
|
347 { |
|
348 if (! (evaluating_function_body && Vsilent_functions)) |
|
349 { |
|
350 bool pad_after = false; |
|
351 |
|
352 if (Vprint_answer_id_name) |
|
353 pad_after = print_name_tag (output_buf, name); |
|
354 |
|
355 print (output_buf); |
|
356 |
|
357 if (print_padding && pad_after) |
|
358 newline (output_buf); |
|
359 } |
|
360 } |
|
361 |
|
362 void |
3933
|
363 octave_base_value::print_info (std::ostream& os, |
4661
|
364 const std::string& /* prefix */) const |
3933
|
365 { |
|
366 os << "no info for type: " << type_name () << "\n"; |
|
367 } |
|
368 |
4254
|
369 #define INT_CONV_METHOD(T, F, MIN_LIMIT, MAX_LIMIT) \ |
|
370 T \ |
|
371 octave_base_value::F ## _value (bool require_int, bool frc_str_conv) const \ |
|
372 { \ |
|
373 T retval = 0; \ |
|
374 \ |
|
375 double d = double_value (frc_str_conv); \ |
|
376 \ |
|
377 if (! error_state) \ |
|
378 { \ |
|
379 if (require_int && D_NINT (d) != d) \ |
|
380 error ("conversion of %g to " #T " value failed", d); \ |
5054
|
381 else if (d < MIN_LIMIT) \ |
|
382 retval = MIN_LIMIT; \ |
|
383 else if (d > MAX_LIMIT) \ |
|
384 retval = MAX_LIMIT; \ |
4254
|
385 else \ |
4732
|
386 retval = static_cast<T> (fix (d)); \ |
4254
|
387 } \ |
|
388 else \ |
|
389 gripe_wrong_type_arg ("octave_base_value::" #F "_value ()", \ |
|
390 type_name ()); \ |
|
391 \ |
|
392 return retval; \ |
|
393 } |
3202
|
394 |
4254
|
395 INT_CONV_METHOD (short int, short, SHRT_MIN, SHRT_MAX) |
|
396 INT_CONV_METHOD (unsigned short int, ushort, 0, USHRT_MAX) |
3202
|
397 |
4254
|
398 INT_CONV_METHOD (int, int, INT_MIN, INT_MAX) |
|
399 INT_CONV_METHOD (unsigned int, uint, 0, UINT_MAX) |
3202
|
400 |
4254
|
401 INT_CONV_METHOD (long int, long, LONG_MIN, LONG_MAX) |
|
402 INT_CONV_METHOD (unsigned long int, ulong, 0, ULONG_MAX) |
3202
|
403 |
|
404 int |
|
405 octave_base_value::nint_value (bool frc_str_conv) const |
|
406 { |
|
407 int retval = 0; |
|
408 |
|
409 double d = double_value (frc_str_conv); |
|
410 |
|
411 if (! error_state) |
|
412 { |
|
413 if (xisnan (d)) |
|
414 { |
|
415 error ("conversion of NaN to integer value failed"); |
|
416 return retval; |
|
417 } |
|
418 |
4732
|
419 retval = static_cast<int> (fix (d)); |
3202
|
420 } |
|
421 else |
|
422 gripe_wrong_type_arg ("octave_base_value::nint_value ()", type_name ()); |
|
423 |
|
424 return retval; |
|
425 } |
|
426 |
2376
|
427 double |
|
428 octave_base_value::double_value (bool) const |
|
429 { |
4102
|
430 double retval = lo_ieee_nan_value (); |
2376
|
431 gripe_wrong_type_arg ("octave_base_value::double_value ()", type_name ()); |
|
432 return retval; |
|
433 } |
|
434 |
3351
|
435 Cell |
3539
|
436 octave_base_value::cell_value () const |
3351
|
437 { |
|
438 Cell retval; |
|
439 gripe_wrong_type_arg ("octave_base_value::cell_value()", type_name ()); |
|
440 return retval; |
|
441 } |
|
442 |
2376
|
443 Matrix |
|
444 octave_base_value::matrix_value (bool) const |
|
445 { |
|
446 Matrix retval; |
|
447 gripe_wrong_type_arg ("octave_base_value::matrix_value()", type_name ()); |
|
448 return retval; |
|
449 } |
|
450 |
4507
|
451 NDArray |
4550
|
452 octave_base_value::array_value (bool) const |
4505
|
453 { |
4507
|
454 NDArray retval; |
4550
|
455 gripe_wrong_type_arg ("octave_base_value::array_value()", type_name ()); |
4505
|
456 return retval; |
|
457 } |
|
458 |
2376
|
459 Complex |
|
460 octave_base_value::complex_value (bool) const |
|
461 { |
4102
|
462 double tmp = lo_ieee_nan_value (); |
|
463 Complex retval (tmp, tmp); |
2376
|
464 gripe_wrong_type_arg ("octave_base_value::complex_value()", type_name ()); |
|
465 return retval; |
|
466 } |
|
467 |
|
468 ComplexMatrix |
|
469 octave_base_value::complex_matrix_value (bool) const |
|
470 { |
|
471 ComplexMatrix retval; |
|
472 gripe_wrong_type_arg ("octave_base_value::complex_matrix_value()", |
|
473 type_name ()); |
|
474 return retval; |
|
475 } |
|
476 |
4550
|
477 ComplexNDArray |
|
478 octave_base_value::complex_array_value (bool) const |
|
479 { |
|
480 ComplexNDArray retval; |
|
481 gripe_wrong_type_arg ("octave_base_value::complex_array_value()", |
|
482 type_name ()); |
|
483 return retval; |
|
484 } |
|
485 |
|
486 bool |
5943
|
487 octave_base_value::bool_value (bool) const |
4550
|
488 { |
|
489 bool retval = false; |
|
490 gripe_wrong_type_arg ("octave_base_value::bool_value()", type_name ()); |
|
491 return retval; |
|
492 } |
|
493 |
|
494 boolMatrix |
5943
|
495 octave_base_value::bool_matrix_value (bool) const |
4550
|
496 { |
|
497 boolMatrix retval; |
|
498 gripe_wrong_type_arg ("octave_base_value::bool_matrix_value()", |
|
499 type_name ()); |
|
500 return retval; |
|
501 } |
|
502 |
|
503 boolNDArray |
5943
|
504 octave_base_value::bool_array_value (bool) const |
4550
|
505 { |
|
506 boolNDArray retval; |
|
507 gripe_wrong_type_arg ("octave_base_value::bool_array_value()", |
|
508 type_name ()); |
|
509 return retval; |
|
510 } |
|
511 |
2376
|
512 charMatrix |
4741
|
513 octave_base_value::char_matrix_value (bool force) const |
2376
|
514 { |
|
515 charMatrix retval; |
4257
|
516 |
4741
|
517 octave_value tmp = convert_to_str (false, force); |
4257
|
518 |
4452
|
519 if (! error_state) |
|
520 retval = tmp.char_matrix_value (); |
|
521 |
2376
|
522 return retval; |
|
523 } |
|
524 |
4550
|
525 charNDArray |
|
526 octave_base_value::char_array_value (bool) const |
|
527 { |
|
528 charNDArray retval; |
|
529 gripe_wrong_type_arg ("octave_base_value::char_array_value()", |
|
530 type_name ()); |
|
531 return retval; |
|
532 } |
|
533 |
5164
|
534 SparseMatrix |
|
535 octave_base_value::sparse_matrix_value (bool) const |
|
536 { |
|
537 SparseMatrix retval; |
|
538 gripe_wrong_type_arg ("octave_base_value::sparse_matrix_value()", type_name ()); |
|
539 return retval; |
|
540 } |
|
541 |
|
542 SparseComplexMatrix |
|
543 octave_base_value::sparse_complex_matrix_value (bool) const |
|
544 { |
|
545 SparseComplexMatrix retval; |
|
546 gripe_wrong_type_arg ("octave_base_value::sparse_complex_matrix_value()", type_name ()); |
|
547 return retval; |
|
548 } |
|
549 |
|
550 SparseBoolMatrix |
|
551 octave_base_value::sparse_bool_matrix_value (bool) const |
|
552 { |
|
553 SparseBoolMatrix retval; |
|
554 gripe_wrong_type_arg ("octave_base_value::sparse_bool_matrix_value()", type_name ()); |
|
555 return retval; |
|
556 } |
|
557 |
4910
|
558 octave_int8 |
|
559 octave_base_value::int8_scalar_value (void) const |
|
560 { |
|
561 octave_int8 retval; |
|
562 gripe_wrong_type_arg ("octave_base_value::int8_scalar_value()", |
|
563 type_name ()); |
|
564 return retval; |
|
565 } |
|
566 |
|
567 octave_int16 |
|
568 octave_base_value::int16_scalar_value (void) const |
|
569 { |
|
570 octave_int16 retval; |
|
571 gripe_wrong_type_arg ("octave_base_value::int16_scalar_value()", |
|
572 type_name ()); |
|
573 return retval; |
|
574 } |
|
575 |
|
576 octave_int32 |
|
577 octave_base_value::int32_scalar_value (void) const |
|
578 { |
|
579 octave_int32 retval; |
|
580 gripe_wrong_type_arg ("octave_base_value::int32_scalar_value()", |
|
581 type_name ()); |
|
582 return retval; |
|
583 } |
|
584 |
|
585 octave_int64 |
|
586 octave_base_value::int64_scalar_value (void) const |
|
587 { |
|
588 octave_int64 retval; |
|
589 gripe_wrong_type_arg ("octave_base_value::int64_scalar_value()", |
|
590 type_name ()); |
|
591 return retval; |
|
592 } |
|
593 |
|
594 octave_uint8 |
|
595 octave_base_value::uint8_scalar_value (void) const |
|
596 { |
|
597 octave_uint8 retval; |
|
598 gripe_wrong_type_arg ("octave_base_value::uint8_scalar_value()", |
|
599 type_name ()); |
|
600 return retval; |
|
601 } |
|
602 |
|
603 octave_uint16 |
|
604 octave_base_value::uint16_scalar_value (void) const |
|
605 { |
|
606 octave_uint16 retval; |
|
607 gripe_wrong_type_arg ("octave_base_value::uint16_scalar_value()", |
|
608 type_name ()); |
|
609 return retval; |
|
610 } |
|
611 |
|
612 octave_uint32 |
|
613 octave_base_value::uint32_scalar_value (void) const |
|
614 { |
|
615 octave_uint32 retval; |
|
616 gripe_wrong_type_arg ("octave_base_value::uint32_scalar_value()", |
|
617 type_name ()); |
|
618 return retval; |
|
619 } |
|
620 |
|
621 octave_uint64 |
|
622 octave_base_value::uint64_scalar_value (void) const |
|
623 { |
|
624 octave_uint64 retval; |
|
625 gripe_wrong_type_arg ("octave_base_value::uint64_scalar_value()", |
|
626 type_name ()); |
|
627 return retval; |
|
628 } |
|
629 |
4906
|
630 int8NDArray |
|
631 octave_base_value::int8_array_value (void) const |
|
632 { |
|
633 int8NDArray retval; |
|
634 gripe_wrong_type_arg ("octave_base_value::int8_array_value()", |
|
635 type_name ()); |
4910
|
636 return retval; |
4906
|
637 } |
|
638 |
|
639 int16NDArray |
|
640 octave_base_value::int16_array_value (void) const |
|
641 { |
|
642 int16NDArray retval; |
|
643 gripe_wrong_type_arg ("octave_base_value::int16_array_value()", |
|
644 type_name ()); |
4910
|
645 return retval; |
4906
|
646 } |
|
647 |
|
648 int32NDArray |
|
649 octave_base_value::int32_array_value (void) const |
|
650 { |
|
651 int32NDArray retval; |
|
652 gripe_wrong_type_arg ("octave_base_value::int32_array_value()", |
|
653 type_name ()); |
4910
|
654 return retval; |
4906
|
655 } |
|
656 |
|
657 int64NDArray |
|
658 octave_base_value::int64_array_value (void) const |
|
659 { |
|
660 int64NDArray retval; |
|
661 gripe_wrong_type_arg ("octave_base_value::int64_array_value()", |
|
662 type_name ()); |
4910
|
663 return retval; |
4906
|
664 } |
|
665 |
|
666 uint8NDArray |
|
667 octave_base_value::uint8_array_value (void) const |
|
668 { |
|
669 uint8NDArray retval; |
|
670 gripe_wrong_type_arg ("octave_base_value::uint8_array_value()", |
|
671 type_name ()); |
4910
|
672 return retval; |
4906
|
673 } |
|
674 |
|
675 uint16NDArray |
|
676 octave_base_value::uint16_array_value (void) const |
|
677 { |
|
678 uint16NDArray retval; |
|
679 gripe_wrong_type_arg ("octave_base_value::uint16_array_value()", |
|
680 type_name ()); |
4910
|
681 return retval; |
4906
|
682 } |
|
683 |
|
684 uint32NDArray |
|
685 octave_base_value::uint32_array_value (void) const |
|
686 { |
|
687 uint32NDArray retval; |
|
688 gripe_wrong_type_arg ("octave_base_value::uint32_array_value()", |
|
689 type_name ()); |
4910
|
690 return retval; |
4906
|
691 } |
|
692 |
|
693 uint64NDArray |
|
694 octave_base_value::uint64_array_value (void) const |
|
695 { |
|
696 uint64NDArray retval; |
|
697 gripe_wrong_type_arg ("octave_base_value::uint64_array_value()", |
|
698 type_name ()); |
4910
|
699 return retval; |
4906
|
700 } |
|
701 |
2493
|
702 string_vector |
5715
|
703 octave_base_value::all_strings (bool pad) const |
2376
|
704 { |
2493
|
705 string_vector retval; |
4257
|
706 |
5715
|
707 octave_value tmp = convert_to_str (pad, true); |
4257
|
708 |
4452
|
709 if (! error_state) |
|
710 retval = tmp.all_strings (); |
4257
|
711 |
2376
|
712 return retval; |
|
713 } |
|
714 |
3536
|
715 std::string |
4457
|
716 octave_base_value::string_value (bool force) const |
2376
|
717 { |
3523
|
718 std::string retval; |
4257
|
719 |
4457
|
720 octave_value tmp = convert_to_str (force); |
4257
|
721 |
4452
|
722 if (! error_state) |
|
723 retval = tmp.string_value (); |
4257
|
724 |
2376
|
725 return retval; |
|
726 } |
|
727 |
|
728 Range |
|
729 octave_base_value::range_value (void) const |
|
730 { |
|
731 Range retval; |
|
732 gripe_wrong_type_arg ("octave_base_value::range_value()", type_name ()); |
|
733 return retval; |
|
734 } |
|
735 |
|
736 Octave_map |
|
737 octave_base_value::map_value (void) const |
|
738 { |
|
739 Octave_map retval; |
|
740 gripe_wrong_type_arg ("octave_base_value::map_value()", type_name ()); |
|
741 return retval; |
|
742 } |
|
743 |
3933
|
744 string_vector |
|
745 octave_base_value::map_keys (void) const |
|
746 { |
|
747 string_vector retval; |
|
748 gripe_wrong_type_arg ("octave_base_value::map_keys()", type_name ()); |
|
749 return retval; |
|
750 } |
|
751 |
4645
|
752 std::streamoff |
4643
|
753 octave_base_value::streamoff_value (void) const |
|
754 { |
4649
|
755 std::streamoff retval (-1); |
4645
|
756 gripe_wrong_type_arg ("octave_base_value::streamoff_value()", type_name ()); |
|
757 return retval; |
|
758 } |
|
759 |
|
760 streamoff_array |
|
761 octave_base_value::streamoff_array_value (void) const |
|
762 { |
4643
|
763 streamoff_array retval; |
4645
|
764 gripe_wrong_type_arg ("octave_base_value::streamoff_array_value()", |
|
765 type_name ()); |
4643
|
766 return retval; |
|
767 } |
|
768 |
2974
|
769 octave_function * |
|
770 octave_base_value::function_value (bool silent) |
|
771 { |
|
772 octave_function *retval = 0; |
|
773 |
|
774 if (! silent) |
|
775 gripe_wrong_type_arg ("octave_base_value::function_value()", |
|
776 type_name ()); |
|
777 return retval; |
|
778 } |
|
779 |
4700
|
780 octave_user_function * |
|
781 octave_base_value::user_function_value (bool silent) |
|
782 { |
|
783 octave_user_function *retval = 0; |
|
784 |
|
785 if (! silent) |
|
786 gripe_wrong_type_arg ("octave_base_value::user_function_value()", |
|
787 type_name ()); |
|
788 return retval; |
|
789 } |
|
790 |
4346
|
791 octave_fcn_handle * |
4343
|
792 octave_base_value::fcn_handle_value (bool silent) |
|
793 { |
4346
|
794 octave_fcn_handle *retval = 0; |
4343
|
795 |
|
796 if (! silent) |
|
797 gripe_wrong_type_arg ("octave_base_value::fcn_handle_value()", |
|
798 type_name ()); |
|
799 return retval; |
|
800 } |
|
801 |
4933
|
802 octave_fcn_inline * |
|
803 octave_base_value::fcn_inline_value (bool silent) |
|
804 { |
|
805 octave_fcn_inline *retval = 0; |
|
806 |
|
807 if (! silent) |
|
808 gripe_wrong_type_arg ("octave_base_value::fcn_inline_value()", |
|
809 type_name ()); |
|
810 return retval; |
|
811 } |
|
812 |
2882
|
813 octave_value_list |
|
814 octave_base_value::list_value (void) const |
|
815 { |
|
816 octave_value_list retval; |
|
817 gripe_wrong_type_arg ("octave_base_value::list_value()", type_name ()); |
|
818 return retval; |
|
819 } |
|
820 |
4687
|
821 bool |
6974
|
822 octave_base_value::save_ascii (std::ostream&) |
4687
|
823 { |
|
824 gripe_wrong_type_arg ("octave_base_value::save_ascii()", type_name ()); |
|
825 return false; |
|
826 } |
|
827 |
|
828 bool |
|
829 octave_base_value::load_ascii (std::istream&) |
|
830 { |
|
831 gripe_wrong_type_arg ("octave_base_value::load_ascii()", type_name ()); |
|
832 return false; |
|
833 } |
|
834 |
|
835 bool |
|
836 octave_base_value::save_binary (std::ostream&, bool&) |
|
837 { |
|
838 gripe_wrong_type_arg ("octave_base_value::save_binary()", type_name ()); |
|
839 return false; |
|
840 } |
|
841 |
|
842 bool |
|
843 octave_base_value::load_binary (std::istream&, bool, |
|
844 oct_mach_info::float_format) |
|
845 { |
|
846 gripe_wrong_type_arg ("octave_base_value::load_binary()", type_name ()); |
|
847 return false; |
|
848 } |
|
849 |
|
850 #if defined (HAVE_HDF5) |
4944
|
851 |
4687
|
852 bool |
|
853 octave_base_value::save_hdf5 (hid_t, const char *, bool) |
|
854 { |
|
855 gripe_wrong_type_arg ("octave_base_value::save_binary()", type_name ()); |
|
856 |
|
857 return false; |
|
858 } |
|
859 |
|
860 bool |
|
861 octave_base_value::load_hdf5 (hid_t, const char *, bool) |
|
862 { |
|
863 gripe_wrong_type_arg ("octave_base_value::load_binary()", type_name ()); |
|
864 |
|
865 return false; |
|
866 } |
4944
|
867 |
4687
|
868 #endif |
|
869 |
4944
|
870 int |
|
871 octave_base_value::write (octave_stream&, int, oct_data_conv::data_type, |
|
872 int, oct_mach_info::float_format) const |
|
873 { |
|
874 gripe_wrong_type_arg ("octave_base_value::write()", type_name ()); |
|
875 |
|
876 return false; |
|
877 } |
|
878 |
5900
|
879 mxArray * |
|
880 octave_base_value::as_mxArray (void) const |
|
881 { |
|
882 gripe_wrong_type_arg ("octave_base_value::as_mxArray ()", type_name ()); |
|
883 |
|
884 return 0; |
|
885 } |
|
886 |
5759
|
887 static void |
|
888 gripe_indexed_assignment (const std::string& tn1, const std::string& tn2) |
|
889 { |
|
890 error ("assignment of `%s' to indexed `%s' not implemented", |
|
891 tn2.c_str (), tn1.c_str ()); |
|
892 } |
|
893 |
|
894 static void |
|
895 gripe_assign_conversion_failed (const std::string& tn1, |
|
896 const std::string& tn2) |
|
897 { |
|
898 error ("type conversion for assignment of `%s' to indexed `%s' failed", |
|
899 tn2.c_str (), tn1.c_str ()); |
|
900 } |
|
901 |
|
902 static void |
|
903 gripe_no_conversion (const std::string& on, const std::string& tn1, |
|
904 const std::string& tn2) |
|
905 { |
|
906 error ("operator %s: no conversion for assignment of `%s' to indexed `%s'", |
|
907 on.c_str (), tn2.c_str (), tn1.c_str ()); |
|
908 } |
|
909 |
|
910 octave_value |
|
911 octave_base_value::numeric_assign (const std::string& type, |
|
912 const std::list<octave_value_list>& idx, |
|
913 const octave_value& rhs) |
|
914 { |
|
915 octave_value retval; |
|
916 |
|
917 int t_lhs = type_id (); |
|
918 int t_rhs = rhs.type_id (); |
|
919 |
|
920 octave_value_typeinfo::assign_op_fcn f |
|
921 = octave_value_typeinfo::lookup_assign_op (octave_value::op_asn_eq, |
|
922 t_lhs, t_rhs); |
|
923 |
|
924 bool done = false; |
|
925 |
|
926 if (f) |
|
927 { |
|
928 f (*this, idx.front (), rhs.get_rep ()); |
|
929 |
|
930 done = (! error_state); |
|
931 } |
|
932 |
|
933 if (done) |
|
934 { |
|
935 count++; |
|
936 retval = octave_value (this); |
|
937 } |
|
938 else |
|
939 { |
|
940 int t_result |
|
941 = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); |
|
942 |
|
943 if (t_result >= 0) |
|
944 { |
|
945 octave_base_value::type_conv_fcn cf |
|
946 = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); |
|
947 |
|
948 if (cf) |
|
949 { |
5874
|
950 octave_base_value *tmp = cf (*this); |
5759
|
951 |
|
952 if (tmp) |
|
953 { |
5874
|
954 octave_value val (tmp); |
|
955 |
|
956 retval = val.subsasgn (type, idx, rhs); |
5759
|
957 |
|
958 done = (! error_state); |
|
959 } |
|
960 else |
|
961 gripe_assign_conversion_failed (type_name (), |
|
962 rhs.type_name ()); |
|
963 } |
|
964 else |
|
965 gripe_indexed_assignment (type_name (), rhs.type_name ()); |
|
966 } |
|
967 |
|
968 if (! (done || error_state)) |
|
969 { |
|
970 octave_value tmp_rhs; |
|
971 |
|
972 octave_base_value::type_conv_fcn cf_rhs |
|
973 = rhs.numeric_conversion_function (); |
|
974 |
|
975 if (cf_rhs) |
|
976 { |
|
977 octave_base_value *tmp = cf_rhs (rhs.get_rep ()); |
|
978 |
|
979 if (tmp) |
|
980 tmp_rhs = octave_value (tmp); |
|
981 else |
|
982 { |
|
983 gripe_assign_conversion_failed (type_name (), |
|
984 rhs.type_name ()); |
|
985 return octave_value (); |
|
986 } |
|
987 } |
|
988 else |
|
989 tmp_rhs = rhs; |
|
990 |
|
991 octave_base_value::type_conv_fcn cf_this |
|
992 = numeric_conversion_function (); |
|
993 |
5897
|
994 count++; |
|
995 octave_value tmp_lhs = octave_value (this); |
5759
|
996 |
|
997 if (cf_this) |
|
998 { |
|
999 octave_base_value *tmp = cf_this (*this); |
|
1000 |
|
1001 if (tmp) |
5897
|
1002 tmp_lhs = octave_value (tmp); |
5759
|
1003 else |
|
1004 { |
|
1005 gripe_assign_conversion_failed (type_name (), |
|
1006 rhs.type_name ()); |
|
1007 return octave_value (); |
|
1008 } |
|
1009 } |
|
1010 |
|
1011 if (cf_this || cf_rhs) |
|
1012 { |
5897
|
1013 retval = tmp_lhs.subsasgn (type, idx, tmp_rhs); |
5759
|
1014 |
|
1015 done = (! error_state); |
|
1016 } |
|
1017 else |
|
1018 gripe_no_conversion (octave_value::assign_op_as_string (octave_value::op_asn_eq), |
|
1019 type_name (), rhs.type_name ()); |
|
1020 } |
|
1021 } |
|
1022 |
|
1023 // The assignment may have converted to a type that is wider than |
|
1024 // necessary. |
|
1025 |
|
1026 retval.maybe_mutate (); |
|
1027 |
|
1028 return retval; |
|
1029 } |
|
1030 |
|
1031 // Current indentation. |
|
1032 int octave_base_value::curr_print_indent_level = 0; |
|
1033 |
|
1034 // TRUE means we are at the beginning of a line. |
|
1035 bool octave_base_value::beginning_of_line = true; |
|
1036 |
|
1037 // Each print() function should call this before printing anything. |
|
1038 // |
|
1039 // This doesn't need to be fast, but isn't there a better way? |
|
1040 |
|
1041 void |
|
1042 octave_base_value::indent (std::ostream& os) const |
|
1043 { |
|
1044 assert (curr_print_indent_level >= 0); |
|
1045 |
|
1046 if (beginning_of_line) |
|
1047 { |
5775
|
1048 // FIXME -- do we need this? |
5759
|
1049 // os << prefix; |
|
1050 |
|
1051 for (int i = 0; i < curr_print_indent_level; i++) |
|
1052 os << " "; |
|
1053 |
|
1054 beginning_of_line = false; |
|
1055 } |
|
1056 } |
|
1057 |
|
1058 // All print() functions should use this to print new lines. |
|
1059 |
|
1060 void |
|
1061 octave_base_value::newline (std::ostream& os) const |
|
1062 { |
|
1063 os << "\n"; |
|
1064 |
|
1065 beginning_of_line = true; |
|
1066 } |
|
1067 |
|
1068 // For ressetting print state. |
|
1069 |
|
1070 void |
|
1071 octave_base_value::reset (void) const |
|
1072 { |
|
1073 beginning_of_line = true; |
|
1074 curr_print_indent_level = 0; |
|
1075 } |
|
1076 |
3203
|
1077 CONVDECLX (matrix_conv) |
2376
|
1078 { |
|
1079 return new octave_matrix (); |
|
1080 } |
|
1081 |
3203
|
1082 CONVDECLX (complex_matrix_conv) |
2376
|
1083 { |
|
1084 return new octave_complex_matrix (); |
|
1085 } |
|
1086 |
3203
|
1087 CONVDECLX (string_conv) |
2376
|
1088 { |
|
1089 return new octave_char_matrix_str (); |
|
1090 } |
|
1091 |
3928
|
1092 CONVDECLX (cell_conv) |
|
1093 { |
|
1094 return new octave_cell (); |
|
1095 } |
|
1096 |
2376
|
1097 void |
|
1098 install_base_type_conversions (void) |
|
1099 { |
|
1100 INSTALL_ASSIGNCONV (octave_base_value, octave_scalar, octave_matrix); |
|
1101 INSTALL_ASSIGNCONV (octave_base_value, octave_matrix, octave_matrix); |
|
1102 INSTALL_ASSIGNCONV (octave_base_value, octave_complex, octave_complex_matrix); |
|
1103 INSTALL_ASSIGNCONV (octave_base_value, octave_complex_matrix, octave_complex_matrix); |
|
1104 INSTALL_ASSIGNCONV (octave_base_value, octave_range, octave_matrix); |
|
1105 INSTALL_ASSIGNCONV (octave_base_value, octave_char_matrix_str, octave_char_matrix_str); |
3928
|
1106 INSTALL_ASSIGNCONV (octave_base_value, octave_cell, octave_cell); |
2376
|
1107 |
|
1108 INSTALL_WIDENOP (octave_base_value, octave_matrix, matrix_conv); |
|
1109 INSTALL_WIDENOP (octave_base_value, octave_complex_matrix, complex_matrix_conv); |
|
1110 INSTALL_WIDENOP (octave_base_value, octave_char_matrix_str, string_conv); |
3928
|
1111 INSTALL_WIDENOP (octave_base_value, octave_cell, cell_conv); |
2376
|
1112 } |
|
1113 |
5794
|
1114 DEFUN (print_answer_id_name, args, nargout, |
|
1115 "-*- texinfo -*-\n\ |
|
1116 @deftypefn {Built-in Function} {@var{val} =} print_answer_id_name ()\n\ |
|
1117 @deftypefnx {Built-in Function} {@var{old_val} =} print_answer_id_name (@var{new_val})\n\ |
|
1118 Query or set the internal variable that controls whether variable\n\ |
|
1119 names are printed along with results produced by evaluating an expression.\n\ |
|
1120 @end deftypefn") |
5759
|
1121 { |
5794
|
1122 return SET_INTERNAL_VARIABLE (print_answer_id_name); |
5759
|
1123 } |
|
1124 |
5794
|
1125 DEFUN (silent_functions, args, nargout, |
|
1126 "-*- texinfo -*-\n\ |
|
1127 @deftypefn {Built-in Function} {@var{val} =} silent_functions ()\n\ |
|
1128 @deftypefnx {Built-in Function} {@var{old_val} =} silent_functions (@var{new_val})\n\ |
|
1129 Query or set the internal variable that controls whether internal\n\ |
|
1130 output from a function is suppressed. If this option is disabled,\n\ |
|
1131 Octave will display the results produced by evaluating expressions\n\ |
|
1132 within a function body that are not terminated with a semicolon.\n\ |
|
1133 @end deftypefn") |
5759
|
1134 { |
5794
|
1135 return SET_INTERNAL_VARIABLE (silent_functions); |
5759
|
1136 } |
|
1137 |
7193
|
1138 DEFUN (sparse_auto_mutate, args, nargout, |
|
1139 "-*- texinfo -*-\n\ |
|
1140 @deftypefn {Built-in Function} {@var{val} =} sparse_auto_mutate ()\n\ |
|
1141 @deftypefnx {Built-in Function} {@var{old_val} =} sparse_auto_mutate (@var{new_val})\n\ |
|
1142 Query or set the internal variable that controls whether Octave will\n\ |
|
1143 automatically mutate sparse matrices to real matrices to save memory.\n\ |
|
1144 For example,\n\ |
|
1145 \n\ |
|
1146 @example\n\ |
|
1147 s = speye(3);\n\ |
|
1148 sparse_auto_mutate (false)\n\ |
|
1149 s (:, 1) = 1;\n\ |
|
1150 typeinfo (s)\n\ |
|
1151 @result{} sparse matrix\n\ |
|
1152 sparse_auto_mutate (true)\n\ |
|
1153 s (1, :) = 1;\n\ |
|
1154 typeinfo (s)\n\ |
|
1155 @result{} matrix\n\ |
|
1156 @end example\n\ |
|
1157 @end deftypefn") |
|
1158 { |
|
1159 return SET_INTERNAL_VARIABLE (sparse_auto_mutate); |
|
1160 } |
|
1161 |
2376
|
1162 /* |
|
1163 ;;; Local Variables: *** |
|
1164 ;;; mode: C++ *** |
|
1165 ;;; End: *** |
|
1166 */ |