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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_value_h) |
|
24 #define octave_value_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2376
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <cstdlib> |
|
31 |
3503
|
32 #include <iostream> |
2376
|
33 #include <string> |
4219
|
34 #include <list> |
2376
|
35 |
4687
|
36 #if defined (HAVE_HDF5) |
|
37 #include <hdf5.h> |
|
38 #endif |
4507
|
39 |
2376
|
40 #include "Range.h" |
|
41 #include "idx-vector.h" |
|
42 #include "mx-base.h" |
2477
|
43 #include "oct-alloc.h" |
4254
|
44 #include "oct-time.h" |
2942
|
45 #include "str-vec.h" |
|
46 |
3351
|
47 class Cell; |
4643
|
48 class streamoff_array; |
2376
|
49 class Octave_map; |
2903
|
50 class octave_stream; |
4643
|
51 class octave_streamoff; |
2974
|
52 class octave_function; |
4700
|
53 class octave_user_function; |
4342
|
54 class octave_fcn_handle; |
4933
|
55 class octave_fcn_inline; |
2376
|
56 class octave_value_list; |
2979
|
57 class octave_lvalue; |
2376
|
58 |
|
59 // Constants. |
|
60 |
|
61 // This just provides a way to avoid infinite recursion when building |
|
62 // octave_value objects. |
|
63 |
|
64 class |
|
65 octave_xvalue |
|
66 { |
|
67 public: |
|
68 |
|
69 octave_xvalue (void) { } |
|
70 }; |
|
71 |
2427
|
72 class octave_value; |
|
73 |
|
74 // XXX FIXME XXX -- these should probably really be inside the scope |
|
75 // of the octave_value class, but the cygwin32 beta16 version of g++ |
3203
|
76 // can't handle that. |
|
77 |
|
78 typedef octave_value (*unary_op_fcn) |
|
79 (const octave_value&); |
|
80 |
|
81 typedef void (*non_const_unary_op_fcn) |
|
82 (octave_value&); |
2427
|
83 |
|
84 typedef octave_value (*binary_op_fcn) |
|
85 (const octave_value&, const octave_value&); |
|
86 |
4915
|
87 typedef octave_value (*cat_op_fcn) |
|
88 (const octave_value&, const octave_value&, const Array<int>& ra_idx); |
|
89 |
2427
|
90 typedef octave_value (*assign_op_fcn) |
|
91 (octave_value&, const octave_value_list&, const octave_value&); |
|
92 |
|
93 typedef octave_value * (*type_conv_fcn) (const octave_value&); |
|
94 |
2376
|
95 class |
2974
|
96 octave_value |
2376
|
97 { |
|
98 public: |
|
99 |
3203
|
100 enum unary_op |
|
101 { |
3525
|
102 op_not, |
|
103 op_uminus, |
|
104 op_transpose, |
|
105 op_hermitian, |
|
106 op_incr, |
|
107 op_decr, |
3203
|
108 num_unary_ops, |
|
109 unknown_unary_op |
|
110 }; |
|
111 |
2376
|
112 enum binary_op |
|
113 { |
3525
|
114 op_add, |
|
115 op_sub, |
|
116 op_mul, |
|
117 op_div, |
|
118 op_pow, |
|
119 op_ldiv, |
|
120 op_lshift, |
|
121 op_rshift, |
|
122 op_lt, |
|
123 op_le, |
|
124 op_eq, |
|
125 op_ge, |
|
126 op_gt, |
|
127 op_ne, |
|
128 op_el_mul, |
|
129 op_el_div, |
|
130 op_el_pow, |
|
131 op_el_ldiv, |
|
132 op_el_and, |
|
133 op_el_or, |
|
134 op_struct_ref, |
2376
|
135 num_binary_ops, |
|
136 unknown_binary_op |
|
137 }; |
|
138 |
2880
|
139 enum assign_op |
|
140 { |
3525
|
141 op_asn_eq, |
|
142 op_add_eq, |
|
143 op_sub_eq, |
|
144 op_mul_eq, |
|
145 op_div_eq, |
|
146 op_ldiv_eq, |
4018
|
147 op_pow_eq, |
3525
|
148 op_lshift_eq, |
|
149 op_rshift_eq, |
|
150 op_el_mul_eq, |
|
151 op_el_div_eq, |
|
152 op_el_ldiv_eq, |
4018
|
153 op_el_pow_eq, |
3525
|
154 op_el_and_eq, |
|
155 op_el_or_eq, |
2880
|
156 num_assign_ops, |
|
157 unknown_assign_op |
|
158 }; |
|
159 |
3523
|
160 static std::string unary_op_as_string (unary_op); |
3203
|
161 |
3523
|
162 static std::string binary_op_as_string (binary_op); |
2376
|
163 |
3523
|
164 static std::string assign_op_as_string (assign_op); |
2880
|
165 |
3933
|
166 static octave_value empty_conv (const std::string& type, |
|
167 const octave_value& rhs = octave_value ()); |
|
168 |
2376
|
169 enum magic_colon { magic_colon_t }; |
|
170 enum all_va_args { all_va_args_t }; |
|
171 |
|
172 octave_value (void); |
4254
|
173 octave_value (short int i); |
|
174 octave_value (unsigned short int i); |
4233
|
175 octave_value (int i); |
4254
|
176 octave_value (unsigned int i); |
|
177 octave_value (long int i); |
|
178 octave_value (unsigned long int i); |
4353
|
179 |
|
180 // XXX FIXME XXX -- these are kluges. They turn into doubles |
|
181 // internally, which will break for very large values. We just use |
|
182 // them to store things like 64-bit ino_t, etc, and hope that those |
|
183 // values are never actually larger than can be represented exactly |
|
184 // in a double. |
|
185 |
|
186 #if defined (HAVE_LONG_LONG_INT) |
|
187 octave_value (long long int i); |
|
188 #endif |
4356
|
189 #if defined (HAVE_UNSIGNED_LONG_LONG_INT) |
4353
|
190 octave_value (unsigned long long int i); |
|
191 #endif |
|
192 |
4254
|
193 octave_value (octave_time t); |
2376
|
194 octave_value (double d); |
4532
|
195 octave_value (const ArrayN<octave_value>& a, bool is_cs_list = false); |
|
196 octave_value (const Cell& c, bool is_cs_list = false); |
2376
|
197 octave_value (const Matrix& m); |
4513
|
198 octave_value (const NDArray& nda); |
4911
|
199 octave_value (const ArrayN<double>& m); |
2376
|
200 octave_value (const DiagMatrix& d); |
3418
|
201 octave_value (const RowVector& v); |
|
202 octave_value (const ColumnVector& v); |
2376
|
203 octave_value (const Complex& C); |
|
204 octave_value (const ComplexMatrix& m); |
4513
|
205 octave_value (const ComplexNDArray& cnda); |
4478
|
206 octave_value (const ArrayN<Complex>& m); |
2376
|
207 octave_value (const ComplexDiagMatrix& d); |
3418
|
208 octave_value (const ComplexRowVector& v); |
|
209 octave_value (const ComplexColumnVector& v); |
2825
|
210 octave_value (bool b); |
|
211 octave_value (const boolMatrix& bm); |
4513
|
212 octave_value (const boolNDArray& bnda); |
3189
|
213 octave_value (char c); |
2376
|
214 octave_value (const char *s); |
3523
|
215 octave_value (const std::string& s); |
2376
|
216 octave_value (const string_vector& s); |
|
217 octave_value (const charMatrix& chm, bool is_string = false); |
4513
|
218 octave_value (const charNDArray& chnda, bool is_string = false); |
4901
|
219 octave_value (const octave_int8& i); |
4910
|
220 octave_value (const octave_int16& i); |
|
221 octave_value (const octave_int32& i); |
|
222 octave_value (const octave_int64& i); |
4901
|
223 octave_value (const octave_uint8& i); |
|
224 octave_value (const octave_uint16& i); |
|
225 octave_value (const octave_uint32& i); |
|
226 octave_value (const octave_uint64& i); |
|
227 octave_value (const int8NDArray& inda); |
4910
|
228 octave_value (const int16NDArray& inda); |
|
229 octave_value (const int32NDArray& inda); |
|
230 octave_value (const int64NDArray& inda); |
4901
|
231 octave_value (const uint8NDArray& inda); |
|
232 octave_value (const uint16NDArray& inda); |
|
233 octave_value (const uint32NDArray& inda); |
|
234 octave_value (const uint64NDArray& inda); |
2376
|
235 octave_value (double base, double limit, double inc); |
|
236 octave_value (const Range& r); |
|
237 octave_value (const Octave_map& m); |
3340
|
238 octave_value (const octave_stream& s, int n); |
4643
|
239 octave_value (const streamoff_array& off); |
3977
|
240 octave_value (const octave_value_list& m, bool is_cs_list = false); |
2376
|
241 octave_value (octave_value::magic_colon); |
|
242 octave_value (octave_value::all_va_args); |
|
243 |
3933
|
244 octave_value (octave_value *new_rep, int count = 1); |
2376
|
245 |
|
246 // Copy constructor. |
|
247 |
|
248 octave_value (const octave_value& a) |
|
249 { |
|
250 rep = a.rep; |
|
251 rep->count++; |
|
252 } |
|
253 |
3933
|
254 // This should only be called for derived types. |
|
255 |
|
256 virtual octave_value *clone (void) const; |
|
257 |
|
258 virtual octave_value *empty_clone (void) const |
|
259 { return rep->empty_clone (); } |
|
260 |
2376
|
261 // Delete the representation of this constant if the count drops to |
|
262 // zero. |
|
263 |
|
264 virtual ~octave_value (void); |
|
265 |
|
266 void make_unique (void) |
|
267 { |
|
268 if (rep->count > 1) |
|
269 { |
|
270 --rep->count; |
|
271 rep = rep->clone (); |
|
272 rep->count = 1; |
|
273 } |
|
274 } |
|
275 |
|
276 // Simple assignment. |
|
277 |
|
278 octave_value& operator = (const octave_value& a) |
|
279 { |
|
280 if (rep != a.rep) |
|
281 { |
|
282 if (--rep->count == 0) |
|
283 delete rep; |
|
284 |
|
285 rep = a.rep; |
|
286 rep->count++; |
|
287 } |
|
288 |
|
289 return *this; |
|
290 } |
|
291 |
3933
|
292 int get_count (void) const { return rep->count; } |
3239
|
293 |
2409
|
294 virtual type_conv_fcn numeric_conversion_function (void) const |
2376
|
295 { return rep->numeric_conversion_function (); } |
|
296 |
2409
|
297 void maybe_mutate (void); |
|
298 |
4532
|
299 virtual octave_value squeeze (void) const |
|
300 { return rep->squeeze (); } |
|
301 |
2410
|
302 virtual octave_value *try_narrowing_conversion (void) |
|
303 { return rep->try_narrowing_conversion (); } |
2409
|
304 |
4271
|
305 octave_value single_subsref (const std::string& type, |
|
306 const octave_value_list& idx); |
|
307 |
4247
|
308 virtual octave_value subsref (const std::string& type, |
4219
|
309 const std::list<octave_value_list>& idx) |
3933
|
310 { return rep->subsref (type, idx); } |
|
311 |
4247
|
312 virtual octave_value_list subsref (const std::string& type, |
4219
|
313 const std::list<octave_value_list>& idx, |
3933
|
314 int nargout); |
|
315 |
4247
|
316 octave_value next_subsref (const std::string& type, const |
4219
|
317 std::list<octave_value_list>& idx, |
4233
|
318 size_t skip = 1); |
3933
|
319 |
|
320 virtual octave_value do_index_op (const octave_value_list& idx, |
|
321 int resize_ok) |
|
322 { return rep->do_index_op (idx, resize_ok); } |
|
323 |
|
324 octave_value do_index_op (const octave_value_list& idx) |
|
325 { return do_index_op (idx, 0); } |
2376
|
326 |
2974
|
327 virtual octave_value_list |
3544
|
328 do_multi_index_op (int nargout, const octave_value_list& idx); |
2974
|
329 |
4247
|
330 virtual octave_value subsasgn (const std::string& type, |
4219
|
331 const std::list<octave_value_list>& idx, |
3933
|
332 const octave_value& rhs); |
2376
|
333 |
4247
|
334 octave_value assign (assign_op op, const std::string& type, |
4219
|
335 const std::list<octave_value_list>& idx, |
3933
|
336 const octave_value& rhs); |
2948
|
337 |
3933
|
338 const octave_value& assign (assign_op, const octave_value& rhs); |
2948
|
339 |
2376
|
340 virtual idx_vector index_vector (void) const |
|
341 { return rep->index_vector (); } |
|
342 |
|
343 // Size. |
|
344 |
4513
|
345 virtual dim_vector dims (void) const |
|
346 { return rep->dims (); } |
|
347 |
4563
|
348 int rows (void) const; |
|
349 |
|
350 int columns (void) const; |
3195
|
351 |
4563
|
352 int length (void) const; |
4554
|
353 |
4563
|
354 int ndims (void) const; |
|
355 |
|
356 int numel (void) const; |
4559
|
357 |
4791
|
358 virtual size_t byte_size (void) const |
|
359 { return rep->byte_size (); } |
|
360 |
4587
|
361 virtual octave_value reshape (const dim_vector& dv) const |
|
362 { return rep->reshape (dv); } |
4567
|
363 |
4593
|
364 virtual octave_value permute (const Array<int>& vec, bool inv = false) const |
|
365 { return rep->permute (vec, inv); } |
|
366 |
|
367 octave_value ipermute (const Array<int>& vec) const |
|
368 { return rep->permute (vec, true); } |
|
369 |
4915
|
370 virtual octave_value resize (const dim_vector& dv) const |
|
371 { return rep->resize (dv);} |
|
372 |
2376
|
373 // Does this constant have a type? Both of these are provided since |
|
374 // it is sometimes more natural to write is_undefined() instead of |
|
375 // ! is_defined(). |
|
376 |
|
377 virtual bool is_defined (void) const |
|
378 { return rep->is_defined (); } |
|
379 |
|
380 bool is_undefined (void) const |
|
381 { return ! is_defined (); } |
|
382 |
4559
|
383 bool is_empty (void) const |
|
384 { return numel () == 0; } |
|
385 |
3351
|
386 virtual bool is_cell (void) const |
|
387 { return rep->is_cell (); } |
|
388 |
2376
|
389 virtual bool is_real_scalar (void) const |
|
390 { return rep->is_real_scalar (); } |
|
391 |
|
392 virtual bool is_real_matrix (void) const |
|
393 { return rep->is_real_matrix (); } |
|
394 |
4505
|
395 virtual bool is_real_nd_array (void) const |
|
396 { return rep->is_real_nd_array (); } |
|
397 |
2376
|
398 virtual bool is_complex_scalar (void) const |
|
399 { return rep->is_complex_scalar (); } |
|
400 |
|
401 virtual bool is_complex_matrix (void) const |
|
402 { return rep->is_complex_matrix (); } |
|
403 |
4587
|
404 virtual bool is_bool_matrix (void) const |
|
405 { return rep->is_bool_matrix (); } |
|
406 |
2376
|
407 virtual bool is_char_matrix (void) const |
|
408 { return rep->is_char_matrix (); } |
|
409 |
|
410 virtual bool is_string (void) const |
|
411 { return rep->is_string (); } |
|
412 |
|
413 virtual bool is_range (void) const |
|
414 { return rep->is_range (); } |
|
415 |
|
416 virtual bool is_map (void) const |
|
417 { return rep->is_map (); } |
|
418 |
3340
|
419 virtual bool is_stream (void) const |
|
420 { return rep->is_stream (); } |
|
421 |
4643
|
422 virtual bool is_streamoff (void) const |
|
423 { return rep->is_streamoff (); } |
|
424 |
3977
|
425 virtual bool is_cs_list (void) const |
|
426 { return rep->is_cs_list (); } |
|
427 |
2880
|
428 virtual bool is_list (void) const |
|
429 { return rep->is_list (); } |
|
430 |
2376
|
431 virtual bool is_magic_colon (void) const |
|
432 { return rep->is_magic_colon (); } |
|
433 |
|
434 virtual bool is_all_va_args (void) const |
|
435 { return rep->is_all_va_args (); } |
|
436 |
|
437 // Are any or all of the elements in this constant nonzero? |
|
438 |
4015
|
439 virtual octave_value all (int dim = 0) const |
|
440 { return rep->all (dim); } |
2376
|
441 |
4015
|
442 virtual octave_value any (int dim = 0) const |
|
443 { return rep->any (dim); } |
2376
|
444 |
|
445 // Other type stuff. |
|
446 |
3209
|
447 virtual bool is_bool_type (void) const |
|
448 { return rep->is_bool_type (); } |
|
449 |
2376
|
450 virtual bool is_real_type (void) const |
|
451 { return rep->is_real_type (); } |
|
452 |
|
453 virtual bool is_complex_type (void) const |
|
454 { return rep->is_complex_type (); } |
|
455 |
|
456 virtual bool is_scalar_type (void) const |
|
457 { return rep->is_scalar_type (); } |
|
458 |
|
459 virtual bool is_matrix_type (void) const |
|
460 { return rep->is_matrix_type (); } |
|
461 |
|
462 virtual bool is_numeric_type (void) const |
|
463 { return rep->is_numeric_type (); } |
|
464 |
|
465 virtual bool valid_as_scalar_index (void) const |
|
466 { return rep->valid_as_scalar_index (); } |
|
467 |
|
468 virtual bool valid_as_zero_index (void) const |
|
469 { return rep->valid_as_zero_index (); } |
|
470 |
|
471 // Does this constant correspond to a truth value? |
|
472 |
|
473 virtual bool is_true (void) const |
|
474 { return rep->is_true (); } |
|
475 |
|
476 // Are the dimensions of this constant zero by zero? |
|
477 |
|
478 virtual bool is_zero_by_zero (void) const |
|
479 { return rep->is_zero_by_zero (); } |
|
480 |
2974
|
481 virtual bool is_constant (void) const |
|
482 { return rep->is_constant (); } |
|
483 |
4654
|
484 virtual bool is_function_handle (void) const |
|
485 { return rep->is_function_handle (); } |
|
486 |
2974
|
487 virtual bool is_function (void) const |
|
488 { return rep->is_function (); } |
2891
|
489 |
3325
|
490 virtual bool is_builtin_function (void) const |
|
491 { return rep->is_builtin_function (); } |
|
492 |
|
493 virtual bool is_dld_function (void) const |
|
494 { return rep->is_dld_function (); } |
|
495 |
2376
|
496 // Values. |
|
497 |
2891
|
498 octave_value eval (void) { return *this; } |
|
499 |
4254
|
500 virtual short int |
|
501 short_value (bool req_int = false, bool frc_str_conv = false) const |
|
502 { return rep->short_value (req_int, frc_str_conv); } |
|
503 |
|
504 virtual unsigned short int |
|
505 ushort_value (bool req_int = false, bool frc_str_conv = false) const |
|
506 { return rep->ushort_value (req_int, frc_str_conv); } |
|
507 |
3202
|
508 virtual int int_value (bool req_int = false, bool frc_str_conv = false) const |
|
509 { return rep->int_value (req_int, frc_str_conv); } |
|
510 |
4254
|
511 virtual unsigned int |
|
512 uint_value (bool req_int = false, bool frc_str_conv = false) const |
|
513 { return rep->uint_value (req_int, frc_str_conv); } |
|
514 |
3202
|
515 virtual int nint_value (bool frc_str_conv = false) const |
|
516 { return rep->nint_value (frc_str_conv); } |
|
517 |
4254
|
518 virtual long int |
|
519 long_value (bool req_int = false, bool frc_str_conv = false) const |
|
520 { return rep->long_value (req_int, frc_str_conv); } |
|
521 |
|
522 virtual unsigned long int |
|
523 ulong_value (bool req_int = false, bool frc_str_conv = false) const |
|
524 { return rep->ulong_value (req_int, frc_str_conv); } |
|
525 |
2376
|
526 virtual double double_value (bool frc_str_conv = false) const |
|
527 { return rep->double_value (frc_str_conv); } |
|
528 |
2916
|
529 virtual double scalar_value (bool frc_str_conv = false) const |
|
530 { return rep->scalar_value (frc_str_conv); } |
|
531 |
3351
|
532 virtual Cell cell_value (void) const; |
|
533 |
2376
|
534 virtual Matrix matrix_value (bool frc_str_conv = false) const |
|
535 { return rep->matrix_value (frc_str_conv); } |
|
536 |
4550
|
537 virtual NDArray array_value (bool frc_str_conv = false) const |
|
538 { return rep->array_value (frc_str_conv); } |
4505
|
539 |
2376
|
540 virtual Complex complex_value (bool frc_str_conv = false) const |
|
541 { return rep->complex_value (frc_str_conv); } |
|
542 |
|
543 virtual ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const |
|
544 { return rep->complex_matrix_value (frc_str_conv); } |
|
545 |
4550
|
546 virtual ComplexNDArray complex_array_value (bool frc_str_conv = false) const |
|
547 { return rep->complex_array_value (frc_str_conv); } |
|
548 |
|
549 virtual bool bool_value (void) const |
|
550 { return rep->bool_value (); } |
|
551 |
|
552 virtual boolMatrix bool_matrix_value (void) const |
|
553 { return rep->bool_matrix_value (); } |
|
554 |
|
555 virtual boolNDArray bool_array_value (void) const |
|
556 { return rep->bool_array_value (); } |
|
557 |
2376
|
558 virtual charMatrix char_matrix_value (bool frc_str_conv = false) const |
|
559 { return rep->char_matrix_value (frc_str_conv); } |
|
560 |
4550
|
561 virtual charNDArray char_array_value (bool frc_str_conv = false) const |
|
562 { return rep->char_array_value (frc_str_conv); } |
|
563 |
4910
|
564 virtual octave_int8 int8_scalar_value (void) const |
|
565 { return rep->int8_scalar_value (); } |
|
566 |
|
567 virtual octave_int16 int16_scalar_value (void) const |
|
568 { return rep->int16_scalar_value (); } |
|
569 |
|
570 virtual octave_int32 int32_scalar_value (void) const |
|
571 { return rep->int32_scalar_value (); } |
|
572 |
|
573 virtual octave_int64 int64_scalar_value (void) const |
|
574 { return rep->int64_scalar_value (); } |
|
575 |
|
576 virtual octave_uint8 uint8_scalar_value (void) const |
|
577 { return rep->uint8_scalar_value (); } |
|
578 |
|
579 virtual octave_uint16 uint16_scalar_value (void) const |
|
580 { return rep->uint16_scalar_value (); } |
|
581 |
|
582 virtual octave_uint32 uint32_scalar_value (void) const |
|
583 { return rep->uint32_scalar_value (); } |
|
584 |
|
585 virtual octave_uint64 uint64_scalar_value (void) const |
|
586 { return rep->uint64_scalar_value (); } |
|
587 |
4906
|
588 virtual int8NDArray int8_array_value (void) const |
|
589 { return rep->int8_array_value (); } |
|
590 |
|
591 virtual int16NDArray int16_array_value (void) const |
|
592 { return rep->int16_array_value (); } |
|
593 |
|
594 virtual int32NDArray int32_array_value (void) const |
|
595 { return rep->int32_array_value (); } |
|
596 |
|
597 virtual int64NDArray int64_array_value (void) const |
|
598 { return rep->int64_array_value (); } |
|
599 |
|
600 virtual uint8NDArray uint8_array_value (void) const |
|
601 { return rep->uint8_array_value (); } |
|
602 |
|
603 virtual uint16NDArray uint16_array_value (void) const |
|
604 { return rep->uint16_array_value (); } |
|
605 |
|
606 virtual uint32NDArray uint32_array_value (void) const |
|
607 { return rep->uint32_array_value (); } |
|
608 |
|
609 virtual uint64NDArray uint64_array_value (void) const |
|
610 { return rep->uint64_array_value (); } |
|
611 |
4457
|
612 virtual string_vector all_strings (bool pad = false, |
|
613 bool force = false) const |
4661
|
614 { return rep->all_strings (pad, force); } |
2376
|
615 |
4457
|
616 virtual std::string string_value (bool force = false) const |
4665
|
617 { return rep->string_value (force); } |
2376
|
618 |
|
619 virtual Range range_value (void) const |
|
620 { return rep->range_value (); } |
|
621 |
|
622 virtual Octave_map map_value (void) const; |
|
623 |
3933
|
624 virtual string_vector map_keys (void) const |
|
625 { return rep->map_keys (); } |
|
626 |
3340
|
627 virtual octave_stream stream_value (void) const; |
2903
|
628 |
|
629 virtual int stream_number (void) const; |
|
630 |
4645
|
631 virtual std::streamoff streamoff_value (void) const; |
|
632 |
|
633 virtual streamoff_array streamoff_array_value (void) const; |
4643
|
634 |
2974
|
635 virtual octave_function *function_value (bool silent = false); |
|
636 |
4700
|
637 virtual octave_user_function *user_function_value (bool silent = false); |
|
638 |
4346
|
639 virtual octave_fcn_handle *fcn_handle_value (bool silent = false); |
4343
|
640 |
4933
|
641 virtual octave_fcn_inline *fcn_inline_value (bool silent = false); |
|
642 |
2880
|
643 virtual octave_value_list list_value (void) const; |
|
644 |
3419
|
645 ColumnVector column_vector_value (bool frc_str_conv = false, |
2376
|
646 bool frc_vec_conv = false) const; |
|
647 |
|
648 ComplexColumnVector |
3419
|
649 complex_column_vector_value (bool frc_str_conv = false, |
2376
|
650 bool frc_vec_conv = false) const; |
|
651 |
3419
|
652 RowVector row_vector_value (bool frc_str_conv = false, |
|
653 bool frc_vec_conv = false) const; |
|
654 |
|
655 ComplexRowVector |
|
656 complex_row_vector_value (bool frc_str_conv = false, |
|
657 bool frc_vec_conv = false) const; |
|
658 |
4044
|
659 Array<int> int_vector_value (bool req_int = false, |
|
660 bool frc_str_conv = false, |
|
661 bool frc_vec_conv = false) const; |
|
662 |
3419
|
663 Array<double> vector_value (bool frc_str_conv = false, |
|
664 bool frc_vec_conv = false) const; |
|
665 |
|
666 Array<Complex> complex_vector_value (bool frc_str_conv = false, |
|
667 bool frc_vec_conv = false) const; |
|
668 |
2376
|
669 // Conversions. These should probably be private. If a user of this |
|
670 // class wants a certain kind of constant, he should simply ask for |
|
671 // it, and we should convert it if possible. |
|
672 |
4457
|
673 octave_value convert_to_str (bool pad = false, bool force = false) const; |
4452
|
674 |
4457
|
675 virtual octave_value convert_to_str_internal (bool pad, bool force) const |
|
676 { return rep->convert_to_str_internal (pad, force); } |
2376
|
677 |
|
678 virtual void convert_to_row_or_column_vector (void) |
|
679 { rep->convert_to_row_or_column_vector (); } |
|
680 |
4604
|
681 virtual bool print_as_scalar (void) const |
|
682 { return rep->print_as_scalar (); } |
|
683 |
3523
|
684 virtual void print (std::ostream& os, bool pr_as_read_syntax = false) const |
2466
|
685 { rep->print (os, pr_as_read_syntax); } |
2376
|
686 |
4457
|
687 virtual void print_raw (std::ostream& os, |
|
688 bool pr_as_read_syntax = false) const |
2903
|
689 { rep->print_raw (os, pr_as_read_syntax); } |
|
690 |
3523
|
691 virtual bool print_name_tag (std::ostream& os, const std::string& name) const |
2903
|
692 { return rep->print_name_tag (os, name); } |
2376
|
693 |
3523
|
694 void print_with_name (std::ostream& os, const std::string& name, |
2903
|
695 bool print_padding = true) const; |
2376
|
696 |
|
697 virtual int type_id (void) const { return rep->type_id (); } |
|
698 |
3523
|
699 virtual std::string type_name (void) const { return rep->type_name (); } |
2376
|
700 |
4612
|
701 virtual std::string class_name (void) const { return rep->class_name (); } |
|
702 |
3203
|
703 // Unary and binary operations. |
|
704 |
3933
|
705 friend octave_value do_unary_op (unary_op op, |
|
706 const octave_value& a); |
3203
|
707 |
3933
|
708 const octave_value& do_non_const_unary_op (unary_op op); |
|
709 |
|
710 void do_non_const_unary_op (unary_op op, const octave_value_list& idx); |
2376
|
711 |
4247
|
712 octave_value do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
713 const std::list<octave_value_list>& idx); |
3205
|
714 |
3933
|
715 friend octave_value do_binary_op (binary_op op, |
|
716 const octave_value& a, |
|
717 const octave_value& b); |
2376
|
718 |
4915
|
719 friend octave_value do_cat_op (const octave_value& a, |
|
720 const octave_value& b, |
|
721 const Array<int>& ra_idx); |
|
722 |
3301
|
723 const octave_value& get_rep (void) const { return *rep; } |
|
724 |
3933
|
725 virtual void print_info (std::ostream& os, |
|
726 const std::string& prefix = std::string ()) const; |
|
727 |
4687
|
728 virtual bool save_ascii (std::ostream& os, bool& infnan_warned, |
|
729 bool strip_nan_and_inf) |
|
730 { return rep->save_ascii (os, infnan_warned, strip_nan_and_inf); } |
|
731 |
|
732 virtual bool load_ascii (std::istream& is) |
|
733 { return rep->load_ascii (is); } |
|
734 |
|
735 virtual bool save_binary (std::ostream& os, bool& save_as_floats) |
|
736 { return rep->save_binary (os, save_as_floats); } |
|
737 |
|
738 virtual bool load_binary (std::istream& is, bool swap, |
|
739 oct_mach_info::float_format fmt) |
|
740 { return rep->load_binary (is, swap, fmt); } |
|
741 |
|
742 #if defined (HAVE_HDF5) |
|
743 virtual bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) |
|
744 { return rep->save_hdf5 (loc_id, name, save_as_floats); } |
|
745 |
|
746 virtual bool load_hdf5 (hid_t loc_id, const char *name, |
|
747 bool have_h5giterate_bug) |
|
748 { return rep->load_hdf5 (loc_id, name, have_h5giterate_bug); } |
|
749 #endif |
|
750 |
4901
|
751 octave_value *internal_rep (void) const { return rep; } |
|
752 |
2376
|
753 protected: |
|
754 |
|
755 octave_value (const octave_xvalue&) : rep (0) { } |
|
756 |
3933
|
757 // This should only be called for derived types. |
|
758 |
4247
|
759 octave_value numeric_assign (const std::string& type, |
4219
|
760 const std::list<octave_value_list>& idx, |
3933
|
761 const octave_value& rhs); |
|
762 |
2903
|
763 void reset_indent_level (void) const |
|
764 { curr_print_indent_level = 0; } |
|
765 |
|
766 void increment_indent_level (void) const |
|
767 { curr_print_indent_level += 2; } |
|
768 |
|
769 void decrement_indent_level (void) const |
|
770 { curr_print_indent_level -= 2; } |
|
771 |
|
772 int current_print_indent_level (void) const |
|
773 { return curr_print_indent_level; } |
|
774 |
3523
|
775 void newline (std::ostream& os) const; |
2903
|
776 |
3523
|
777 void indent (std::ostream& os) const; |
2903
|
778 |
|
779 void reset (void) const; |
|
780 |
2376
|
781 union |
|
782 { |
|
783 octave_value *rep; // The real representation. |
|
784 int count; // A reference count. |
|
785 }; |
2413
|
786 |
3933
|
787 private: |
2903
|
788 |
|
789 static int curr_print_indent_level; |
|
790 static bool beginning_of_line; |
3204
|
791 |
3205
|
792 assign_op unary_op_to_assign_op (unary_op op); |
|
793 |
3204
|
794 binary_op op_eq_to_binary_op (assign_op op); |
|
795 |
3219
|
796 DECLARE_OCTAVE_ALLOCATOR |
4513
|
797 |
|
798 octave_value *nil_rep (void) const; |
2376
|
799 }; |
|
800 |
3203
|
801 #define OV_UNOP_FN(name) \ |
|
802 inline octave_value \ |
|
803 name (const octave_value& a) \ |
|
804 { \ |
|
805 return do_unary_op (octave_value::name, a); \ |
|
806 } |
|
807 |
|
808 #define OV_UNOP_OP(name, op) \ |
|
809 inline octave_value \ |
|
810 operator op (const octave_value& a) \ |
|
811 { \ |
|
812 return name (a); \ |
|
813 } |
|
814 |
|
815 #define OV_UNOP_FN_OP(name, op) \ |
|
816 OV_UNOP_FN (name) \ |
|
817 OV_UNOP_OP (name, op) |
|
818 |
3525
|
819 OV_UNOP_FN_OP (op_not, !) |
|
820 OV_UNOP_FN_OP (op_uminus, -) |
3203
|
821 |
3525
|
822 OV_UNOP_FN (op_transpose) |
|
823 OV_UNOP_FN (op_hermitian) |
3203
|
824 |
|
825 // No simple way to define these for prefix and suffix ops? |
|
826 // |
|
827 // incr |
|
828 // decr |
|
829 |
|
830 #define OV_BINOP_FN(name) \ |
|
831 inline octave_value \ |
|
832 name (const octave_value& a1, const octave_value& a2) \ |
|
833 { \ |
|
834 return do_binary_op (octave_value::name, a1, a2); \ |
|
835 } |
|
836 |
|
837 #define OV_BINOP_OP(name, op) \ |
|
838 inline octave_value \ |
|
839 operator op (const octave_value& a1, const octave_value& a2) \ |
|
840 { \ |
|
841 return name (a1, a2); \ |
|
842 } |
|
843 |
|
844 #define OV_BINOP_FN_OP(name, op) \ |
|
845 OV_BINOP_FN (name) \ |
|
846 OV_BINOP_OP (name, op) |
|
847 |
3525
|
848 OV_BINOP_FN_OP (op_add, +) |
|
849 OV_BINOP_FN_OP (op_sub, -) |
|
850 OV_BINOP_FN_OP (op_mul, *) |
|
851 OV_BINOP_FN_OP (op_div, /) |
3203
|
852 |
3525
|
853 OV_BINOP_FN (op_pow) |
|
854 OV_BINOP_FN (op_ldiv) |
|
855 OV_BINOP_FN (op_lshift) |
|
856 OV_BINOP_FN (op_rshift) |
3203
|
857 |
3525
|
858 OV_BINOP_FN_OP (op_lt, <) |
|
859 OV_BINOP_FN_OP (op_le, <=) |
|
860 OV_BINOP_FN_OP (op_eq, ==) |
|
861 OV_BINOP_FN_OP (op_ge, >=) |
|
862 OV_BINOP_FN_OP (op_gt, >) |
|
863 OV_BINOP_FN_OP (op_ne, !=) |
3203
|
864 |
3525
|
865 OV_BINOP_FN (op_el_mul) |
|
866 OV_BINOP_FN (op_el_div) |
|
867 OV_BINOP_FN (op_el_pow) |
|
868 OV_BINOP_FN (op_el_ldiv) |
|
869 OV_BINOP_FN (op_el_and) |
|
870 OV_BINOP_FN (op_el_or) |
3203
|
871 |
3525
|
872 OV_BINOP_FN (op_struct_ref) |
3203
|
873 |
3219
|
874 // T_ID is the type id of struct objects, set by register_type(). |
|
875 // T_NAME is the type name of struct objects. |
|
876 #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA \ |
|
877 public: \ |
|
878 int type_id (void) const { return t_id; } \ |
3523
|
879 std::string type_name (void) const { return t_name; } \ |
4612
|
880 std::string class_name (void) const { return c_name; } \ |
4252
|
881 static int static_type_id (void) { return t_id; } \ |
4901
|
882 static std::string static_type_name (void) { return t_name; } \ |
|
883 static std::string static_class_name (void) { return c_name; } \ |
4640
|
884 static void register_type (void); \ |
3219
|
885 \ |
|
886 private: \ |
4252
|
887 static int t_id; \ |
4612
|
888 static const std::string t_name; \ |
|
889 static const std::string c_name; |
3219
|
890 |
4612
|
891 #define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c) \ |
4252
|
892 int t::t_id (-1); \ |
4612
|
893 const std::string t::t_name (n); \ |
4640
|
894 const std::string t::c_name (c); \ |
|
895 void t::register_type (void) \ |
|
896 { \ |
|
897 t_id = octave_value_typeinfo::register_type (t::t_name, \ |
|
898 t::c_name, \ |
4645
|
899 octave_value (new t ())); \ |
4640
|
900 } |
3219
|
901 |
4455
|
902 // If TRUE, print a warning for assignments like |
2376
|
903 // |
|
904 // octave> A(1) = 3; A(2) = 5 |
|
905 // |
|
906 // for A already defined and a matrix type. |
4455
|
907 extern bool Vwarn_fortran_indexing; |
2376
|
908 |
4452
|
909 // Should we print a warning when converting `[97, 98, 99, "123"]' |
|
910 // to a character string? |
|
911 extern bool Vwarn_num_to_str; |
4257
|
912 |
4452
|
913 // If TRUE, warn for operations like |
2376
|
914 // |
|
915 // octave> 'abc' + 0 |
|
916 // 97 98 99 |
|
917 // |
4452
|
918 extern int Vwarn_str_to_num; |
2376
|
919 |
4451
|
920 // Should we warn about conversions from complex to real? |
|
921 extern int Vwarn_imag_to_real; |
2376
|
922 |
|
923 // If TRUE, print the name along with the value. |
|
924 extern bool Vprint_answer_id_name; |
|
925 |
|
926 // How many levels of structure elements should we print? |
|
927 extern int Vstruct_levels_to_print; |
|
928 |
|
929 // Allow divide by zero errors to be suppressed. |
|
930 extern bool Vwarn_divide_by_zero; |
|
931 |
4461
|
932 // If TRUE, print a warning when a matrix is resized by an indexed |
|
933 // assignment with indices outside the current bounds. |
|
934 extern bool Vwarn_resize_on_range_error; |
3195
|
935 |
2376
|
936 // Indentation level for structures. |
|
937 extern int struct_indent; |
|
938 |
|
939 extern void increment_struct_indent (void); |
|
940 extern void decrement_struct_indent (void); |
|
941 |
2880
|
942 // Indentation level for lists. |
|
943 extern int list_indent; |
|
944 |
|
945 extern void increment_list_indent (void); |
|
946 extern void decrement_list_indent (void); |
|
947 |
2376
|
948 extern void install_types (void); |
|
949 |
|
950 #endif |
|
951 |
|
952 /* |
|
953 ;; Local Variables: *** |
|
954 ;; mode: C++ *** |
|
955 ;; End: *** |
|
956 */ |