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