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