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