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 |
|
363 int numel (void) const; |
4559
|
364 |
4791
|
365 virtual size_t byte_size (void) const |
|
366 { return rep->byte_size (); } |
|
367 |
4587
|
368 virtual octave_value reshape (const dim_vector& dv) const |
|
369 { return rep->reshape (dv); } |
4567
|
370 |
4593
|
371 virtual octave_value permute (const Array<int>& vec, bool inv = false) const |
|
372 { return rep->permute (vec, inv); } |
|
373 |
|
374 octave_value ipermute (const Array<int>& vec) const |
|
375 { return rep->permute (vec, true); } |
|
376 |
4915
|
377 virtual octave_value resize (const dim_vector& dv) const |
|
378 { return rep->resize (dv);} |
|
379 |
2376
|
380 // Does this constant have a type? Both of these are provided since |
|
381 // it is sometimes more natural to write is_undefined() instead of |
|
382 // ! is_defined(). |
|
383 |
|
384 virtual bool is_defined (void) const |
|
385 { return rep->is_defined (); } |
|
386 |
|
387 bool is_undefined (void) const |
|
388 { return ! is_defined (); } |
|
389 |
4559
|
390 bool is_empty (void) const |
|
391 { return numel () == 0; } |
|
392 |
3351
|
393 virtual bool is_cell (void) const |
|
394 { return rep->is_cell (); } |
|
395 |
2376
|
396 virtual bool is_real_scalar (void) const |
|
397 { return rep->is_real_scalar (); } |
|
398 |
|
399 virtual bool is_real_matrix (void) const |
|
400 { return rep->is_real_matrix (); } |
|
401 |
4505
|
402 virtual bool is_real_nd_array (void) const |
|
403 { return rep->is_real_nd_array (); } |
|
404 |
2376
|
405 virtual bool is_complex_scalar (void) const |
|
406 { return rep->is_complex_scalar (); } |
|
407 |
|
408 virtual bool is_complex_matrix (void) const |
|
409 { return rep->is_complex_matrix (); } |
|
410 |
4587
|
411 virtual bool is_bool_matrix (void) const |
|
412 { return rep->is_bool_matrix (); } |
|
413 |
2376
|
414 virtual bool is_char_matrix (void) const |
|
415 { return rep->is_char_matrix (); } |
|
416 |
|
417 virtual bool is_string (void) const |
|
418 { return rep->is_string (); } |
|
419 |
|
420 virtual bool is_range (void) const |
|
421 { return rep->is_range (); } |
|
422 |
|
423 virtual bool is_map (void) const |
|
424 { return rep->is_map (); } |
|
425 |
3340
|
426 virtual bool is_stream (void) const |
|
427 { return rep->is_stream (); } |
|
428 |
4643
|
429 virtual bool is_streamoff (void) const |
|
430 { return rep->is_streamoff (); } |
|
431 |
3977
|
432 virtual bool is_cs_list (void) const |
|
433 { return rep->is_cs_list (); } |
|
434 |
2880
|
435 virtual bool is_list (void) const |
|
436 { return rep->is_list (); } |
|
437 |
2376
|
438 virtual bool is_magic_colon (void) const |
|
439 { return rep->is_magic_colon (); } |
|
440 |
|
441 virtual bool is_all_va_args (void) const |
|
442 { return rep->is_all_va_args (); } |
|
443 |
|
444 // Are any or all of the elements in this constant nonzero? |
|
445 |
4015
|
446 virtual octave_value all (int dim = 0) const |
|
447 { return rep->all (dim); } |
2376
|
448 |
4015
|
449 virtual octave_value any (int dim = 0) const |
|
450 { return rep->any (dim); } |
2376
|
451 |
|
452 // Other type stuff. |
|
453 |
3209
|
454 virtual bool is_bool_type (void) const |
|
455 { return rep->is_bool_type (); } |
|
456 |
2376
|
457 virtual bool is_real_type (void) const |
|
458 { return rep->is_real_type (); } |
|
459 |
|
460 virtual bool is_complex_type (void) const |
|
461 { return rep->is_complex_type (); } |
|
462 |
|
463 virtual bool is_scalar_type (void) const |
|
464 { return rep->is_scalar_type (); } |
|
465 |
|
466 virtual bool is_matrix_type (void) const |
|
467 { return rep->is_matrix_type (); } |
|
468 |
|
469 virtual bool is_numeric_type (void) const |
|
470 { return rep->is_numeric_type (); } |
|
471 |
|
472 virtual bool valid_as_scalar_index (void) const |
|
473 { return rep->valid_as_scalar_index (); } |
|
474 |
|
475 virtual bool valid_as_zero_index (void) const |
|
476 { return rep->valid_as_zero_index (); } |
|
477 |
|
478 // Does this constant correspond to a truth value? |
|
479 |
|
480 virtual bool is_true (void) const |
|
481 { return rep->is_true (); } |
|
482 |
|
483 // Are the dimensions of this constant zero by zero? |
|
484 |
|
485 virtual bool is_zero_by_zero (void) const |
|
486 { return rep->is_zero_by_zero (); } |
|
487 |
2974
|
488 virtual bool is_constant (void) const |
|
489 { return rep->is_constant (); } |
|
490 |
4654
|
491 virtual bool is_function_handle (void) const |
|
492 { return rep->is_function_handle (); } |
|
493 |
4954
|
494 virtual bool is_inline_function (void) const |
|
495 { return rep->is_inline_function (); } |
|
496 |
2974
|
497 virtual bool is_function (void) const |
|
498 { return rep->is_function (); } |
2891
|
499 |
3325
|
500 virtual bool is_builtin_function (void) const |
|
501 { return rep->is_builtin_function (); } |
|
502 |
|
503 virtual bool is_dld_function (void) const |
|
504 { return rep->is_dld_function (); } |
|
505 |
2376
|
506 // Values. |
|
507 |
2891
|
508 octave_value eval (void) { return *this; } |
|
509 |
4254
|
510 virtual short int |
|
511 short_value (bool req_int = false, bool frc_str_conv = false) const |
|
512 { return rep->short_value (req_int, frc_str_conv); } |
|
513 |
|
514 virtual unsigned short int |
|
515 ushort_value (bool req_int = false, bool frc_str_conv = false) const |
|
516 { return rep->ushort_value (req_int, frc_str_conv); } |
|
517 |
3202
|
518 virtual int int_value (bool req_int = false, bool frc_str_conv = false) const |
|
519 { return rep->int_value (req_int, frc_str_conv); } |
|
520 |
4254
|
521 virtual unsigned int |
|
522 uint_value (bool req_int = false, bool frc_str_conv = false) const |
|
523 { return rep->uint_value (req_int, frc_str_conv); } |
|
524 |
3202
|
525 virtual int nint_value (bool frc_str_conv = false) const |
|
526 { return rep->nint_value (frc_str_conv); } |
|
527 |
4254
|
528 virtual long int |
|
529 long_value (bool req_int = false, bool frc_str_conv = false) const |
|
530 { return rep->long_value (req_int, frc_str_conv); } |
|
531 |
|
532 virtual unsigned long int |
|
533 ulong_value (bool req_int = false, bool frc_str_conv = false) const |
|
534 { return rep->ulong_value (req_int, frc_str_conv); } |
|
535 |
2376
|
536 virtual double double_value (bool frc_str_conv = false) const |
|
537 { return rep->double_value (frc_str_conv); } |
|
538 |
2916
|
539 virtual double scalar_value (bool frc_str_conv = false) const |
|
540 { return rep->scalar_value (frc_str_conv); } |
|
541 |
3351
|
542 virtual Cell cell_value (void) const; |
|
543 |
2376
|
544 virtual Matrix matrix_value (bool frc_str_conv = false) const |
|
545 { return rep->matrix_value (frc_str_conv); } |
|
546 |
4550
|
547 virtual NDArray array_value (bool frc_str_conv = false) const |
|
548 { return rep->array_value (frc_str_conv); } |
4505
|
549 |
2376
|
550 virtual Complex complex_value (bool frc_str_conv = false) const |
|
551 { return rep->complex_value (frc_str_conv); } |
|
552 |
|
553 virtual ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const |
|
554 { return rep->complex_matrix_value (frc_str_conv); } |
|
555 |
4550
|
556 virtual ComplexNDArray complex_array_value (bool frc_str_conv = false) const |
|
557 { return rep->complex_array_value (frc_str_conv); } |
|
558 |
|
559 virtual bool bool_value (void) const |
|
560 { return rep->bool_value (); } |
|
561 |
|
562 virtual boolMatrix bool_matrix_value (void) const |
|
563 { return rep->bool_matrix_value (); } |
|
564 |
|
565 virtual boolNDArray bool_array_value (void) const |
|
566 { return rep->bool_array_value (); } |
|
567 |
2376
|
568 virtual charMatrix char_matrix_value (bool frc_str_conv = false) const |
|
569 { return rep->char_matrix_value (frc_str_conv); } |
|
570 |
4550
|
571 virtual charNDArray char_array_value (bool frc_str_conv = false) const |
|
572 { return rep->char_array_value (frc_str_conv); } |
|
573 |
4910
|
574 virtual octave_int8 int8_scalar_value (void) const |
|
575 { return rep->int8_scalar_value (); } |
|
576 |
|
577 virtual octave_int16 int16_scalar_value (void) const |
|
578 { return rep->int16_scalar_value (); } |
|
579 |
|
580 virtual octave_int32 int32_scalar_value (void) const |
|
581 { return rep->int32_scalar_value (); } |
|
582 |
|
583 virtual octave_int64 int64_scalar_value (void) const |
|
584 { return rep->int64_scalar_value (); } |
|
585 |
|
586 virtual octave_uint8 uint8_scalar_value (void) const |
|
587 { return rep->uint8_scalar_value (); } |
|
588 |
|
589 virtual octave_uint16 uint16_scalar_value (void) const |
|
590 { return rep->uint16_scalar_value (); } |
|
591 |
|
592 virtual octave_uint32 uint32_scalar_value (void) const |
|
593 { return rep->uint32_scalar_value (); } |
|
594 |
|
595 virtual octave_uint64 uint64_scalar_value (void) const |
|
596 { return rep->uint64_scalar_value (); } |
|
597 |
4906
|
598 virtual int8NDArray int8_array_value (void) const |
|
599 { return rep->int8_array_value (); } |
|
600 |
|
601 virtual int16NDArray int16_array_value (void) const |
|
602 { return rep->int16_array_value (); } |
|
603 |
|
604 virtual int32NDArray int32_array_value (void) const |
|
605 { return rep->int32_array_value (); } |
|
606 |
|
607 virtual int64NDArray int64_array_value (void) const |
|
608 { return rep->int64_array_value (); } |
|
609 |
|
610 virtual uint8NDArray uint8_array_value (void) const |
|
611 { return rep->uint8_array_value (); } |
|
612 |
|
613 virtual uint16NDArray uint16_array_value (void) const |
|
614 { return rep->uint16_array_value (); } |
|
615 |
|
616 virtual uint32NDArray uint32_array_value (void) const |
|
617 { return rep->uint32_array_value (); } |
|
618 |
|
619 virtual uint64NDArray uint64_array_value (void) const |
|
620 { return rep->uint64_array_value (); } |
|
621 |
4457
|
622 virtual string_vector all_strings (bool pad = false, |
|
623 bool force = false) const |
4661
|
624 { return rep->all_strings (pad, force); } |
2376
|
625 |
4457
|
626 virtual std::string string_value (bool force = false) const |
4665
|
627 { return rep->string_value (force); } |
2376
|
628 |
|
629 virtual Range range_value (void) const |
|
630 { return rep->range_value (); } |
|
631 |
|
632 virtual Octave_map map_value (void) const; |
|
633 |
3933
|
634 virtual string_vector map_keys (void) const |
|
635 { return rep->map_keys (); } |
|
636 |
3340
|
637 virtual octave_stream stream_value (void) const; |
2903
|
638 |
|
639 virtual int stream_number (void) const; |
|
640 |
4645
|
641 virtual std::streamoff streamoff_value (void) const; |
|
642 |
|
643 virtual streamoff_array streamoff_array_value (void) const; |
4643
|
644 |
2974
|
645 virtual octave_function *function_value (bool silent = false); |
|
646 |
4700
|
647 virtual octave_user_function *user_function_value (bool silent = false); |
|
648 |
4346
|
649 virtual octave_fcn_handle *fcn_handle_value (bool silent = false); |
4343
|
650 |
4933
|
651 virtual octave_fcn_inline *fcn_inline_value (bool silent = false); |
|
652 |
2880
|
653 virtual octave_value_list list_value (void) const; |
|
654 |
3419
|
655 ColumnVector column_vector_value (bool frc_str_conv = false, |
2376
|
656 bool frc_vec_conv = false) const; |
|
657 |
|
658 ComplexColumnVector |
3419
|
659 complex_column_vector_value (bool frc_str_conv = false, |
2376
|
660 bool frc_vec_conv = false) const; |
|
661 |
3419
|
662 RowVector row_vector_value (bool frc_str_conv = false, |
|
663 bool frc_vec_conv = false) const; |
|
664 |
|
665 ComplexRowVector |
|
666 complex_row_vector_value (bool frc_str_conv = false, |
|
667 bool frc_vec_conv = false) const; |
|
668 |
4044
|
669 Array<int> int_vector_value (bool req_int = false, |
|
670 bool frc_str_conv = false, |
|
671 bool frc_vec_conv = false) const; |
|
672 |
3419
|
673 Array<double> vector_value (bool frc_str_conv = false, |
|
674 bool frc_vec_conv = false) const; |
|
675 |
|
676 Array<Complex> complex_vector_value (bool frc_str_conv = false, |
|
677 bool frc_vec_conv = false) const; |
|
678 |
2376
|
679 // Conversions. These should probably be private. If a user of this |
|
680 // class wants a certain kind of constant, he should simply ask for |
|
681 // it, and we should convert it if possible. |
|
682 |
4457
|
683 octave_value convert_to_str (bool pad = false, bool force = false) const; |
4452
|
684 |
4457
|
685 virtual octave_value convert_to_str_internal (bool pad, bool force) const |
|
686 { return rep->convert_to_str_internal (pad, force); } |
2376
|
687 |
|
688 virtual void convert_to_row_or_column_vector (void) |
|
689 { rep->convert_to_row_or_column_vector (); } |
|
690 |
4604
|
691 virtual bool print_as_scalar (void) const |
|
692 { return rep->print_as_scalar (); } |
|
693 |
3523
|
694 virtual void print (std::ostream& os, bool pr_as_read_syntax = false) const |
2466
|
695 { rep->print (os, pr_as_read_syntax); } |
2376
|
696 |
4457
|
697 virtual void print_raw (std::ostream& os, |
|
698 bool pr_as_read_syntax = false) const |
2903
|
699 { rep->print_raw (os, pr_as_read_syntax); } |
|
700 |
3523
|
701 virtual bool print_name_tag (std::ostream& os, const std::string& name) const |
2903
|
702 { return rep->print_name_tag (os, name); } |
2376
|
703 |
3523
|
704 void print_with_name (std::ostream& os, const std::string& name, |
2903
|
705 bool print_padding = true) const; |
2376
|
706 |
|
707 virtual int type_id (void) const { return rep->type_id (); } |
|
708 |
3523
|
709 virtual std::string type_name (void) const { return rep->type_name (); } |
2376
|
710 |
4612
|
711 virtual std::string class_name (void) const { return rep->class_name (); } |
|
712 |
3203
|
713 // Unary and binary operations. |
|
714 |
3933
|
715 friend octave_value do_unary_op (unary_op op, |
|
716 const octave_value& a); |
3203
|
717 |
3933
|
718 const octave_value& do_non_const_unary_op (unary_op op); |
|
719 |
|
720 void do_non_const_unary_op (unary_op op, const octave_value_list& idx); |
2376
|
721 |
4247
|
722 octave_value do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
723 const std::list<octave_value_list>& idx); |
3205
|
724 |
3933
|
725 friend octave_value do_binary_op (binary_op op, |
|
726 const octave_value& a, |
|
727 const octave_value& b); |
2376
|
728 |
4915
|
729 friend octave_value do_cat_op (const octave_value& a, |
|
730 const octave_value& b, |
|
731 const Array<int>& ra_idx); |
|
732 |
3301
|
733 const octave_value& get_rep (void) const { return *rep; } |
|
734 |
3933
|
735 virtual void print_info (std::ostream& os, |
|
736 const std::string& prefix = std::string ()) const; |
|
737 |
4687
|
738 virtual bool save_ascii (std::ostream& os, bool& infnan_warned, |
|
739 bool strip_nan_and_inf) |
|
740 { return rep->save_ascii (os, infnan_warned, strip_nan_and_inf); } |
|
741 |
|
742 virtual bool load_ascii (std::istream& is) |
|
743 { return rep->load_ascii (is); } |
|
744 |
|
745 virtual bool save_binary (std::ostream& os, bool& save_as_floats) |
|
746 { return rep->save_binary (os, save_as_floats); } |
|
747 |
|
748 virtual bool load_binary (std::istream& is, bool swap, |
|
749 oct_mach_info::float_format fmt) |
|
750 { return rep->load_binary (is, swap, fmt); } |
|
751 |
|
752 #if defined (HAVE_HDF5) |
|
753 virtual bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) |
|
754 { return rep->save_hdf5 (loc_id, name, save_as_floats); } |
|
755 |
|
756 virtual bool load_hdf5 (hid_t loc_id, const char *name, |
|
757 bool have_h5giterate_bug) |
|
758 { return rep->load_hdf5 (loc_id, name, have_h5giterate_bug); } |
|
759 #endif |
|
760 |
4944
|
761 virtual int write (octave_stream& os, int block_size, |
|
762 oct_data_conv::data_type output_type, int skip, |
|
763 oct_mach_info::float_format flt_fmt) const; |
|
764 |
4901
|
765 octave_value *internal_rep (void) const { return rep; } |
|
766 |
2376
|
767 protected: |
|
768 |
|
769 octave_value (const octave_xvalue&) : rep (0) { } |
|
770 |
3933
|
771 // This should only be called for derived types. |
|
772 |
4247
|
773 octave_value numeric_assign (const std::string& type, |
4219
|
774 const std::list<octave_value_list>& idx, |
3933
|
775 const octave_value& rhs); |
|
776 |
2903
|
777 void reset_indent_level (void) const |
|
778 { curr_print_indent_level = 0; } |
|
779 |
|
780 void increment_indent_level (void) const |
|
781 { curr_print_indent_level += 2; } |
|
782 |
|
783 void decrement_indent_level (void) const |
|
784 { curr_print_indent_level -= 2; } |
|
785 |
|
786 int current_print_indent_level (void) const |
|
787 { return curr_print_indent_level; } |
|
788 |
3523
|
789 void newline (std::ostream& os) const; |
2903
|
790 |
3523
|
791 void indent (std::ostream& os) const; |
2903
|
792 |
|
793 void reset (void) const; |
|
794 |
2376
|
795 union |
|
796 { |
|
797 octave_value *rep; // The real representation. |
|
798 int count; // A reference count. |
|
799 }; |
2413
|
800 |
3933
|
801 private: |
2903
|
802 |
|
803 static int curr_print_indent_level; |
|
804 static bool beginning_of_line; |
3204
|
805 |
3205
|
806 assign_op unary_op_to_assign_op (unary_op op); |
|
807 |
3204
|
808 binary_op op_eq_to_binary_op (assign_op op); |
|
809 |
3219
|
810 DECLARE_OCTAVE_ALLOCATOR |
4513
|
811 |
|
812 octave_value *nil_rep (void) const; |
2376
|
813 }; |
|
814 |
3203
|
815 #define OV_UNOP_FN(name) \ |
|
816 inline octave_value \ |
|
817 name (const octave_value& a) \ |
|
818 { \ |
|
819 return do_unary_op (octave_value::name, a); \ |
|
820 } |
|
821 |
|
822 #define OV_UNOP_OP(name, op) \ |
|
823 inline octave_value \ |
|
824 operator op (const octave_value& a) \ |
|
825 { \ |
|
826 return name (a); \ |
|
827 } |
|
828 |
|
829 #define OV_UNOP_FN_OP(name, op) \ |
|
830 OV_UNOP_FN (name) \ |
|
831 OV_UNOP_OP (name, op) |
|
832 |
3525
|
833 OV_UNOP_FN_OP (op_not, !) |
|
834 OV_UNOP_FN_OP (op_uminus, -) |
3203
|
835 |
3525
|
836 OV_UNOP_FN (op_transpose) |
|
837 OV_UNOP_FN (op_hermitian) |
3203
|
838 |
|
839 // No simple way to define these for prefix and suffix ops? |
|
840 // |
|
841 // incr |
|
842 // decr |
|
843 |
|
844 #define OV_BINOP_FN(name) \ |
|
845 inline octave_value \ |
|
846 name (const octave_value& a1, const octave_value& a2) \ |
|
847 { \ |
|
848 return do_binary_op (octave_value::name, a1, a2); \ |
|
849 } |
|
850 |
|
851 #define OV_BINOP_OP(name, op) \ |
|
852 inline octave_value \ |
|
853 operator op (const octave_value& a1, const octave_value& a2) \ |
|
854 { \ |
|
855 return name (a1, a2); \ |
|
856 } |
|
857 |
|
858 #define OV_BINOP_FN_OP(name, op) \ |
|
859 OV_BINOP_FN (name) \ |
|
860 OV_BINOP_OP (name, op) |
|
861 |
3525
|
862 OV_BINOP_FN_OP (op_add, +) |
|
863 OV_BINOP_FN_OP (op_sub, -) |
|
864 OV_BINOP_FN_OP (op_mul, *) |
|
865 OV_BINOP_FN_OP (op_div, /) |
3203
|
866 |
3525
|
867 OV_BINOP_FN (op_pow) |
|
868 OV_BINOP_FN (op_ldiv) |
|
869 OV_BINOP_FN (op_lshift) |
|
870 OV_BINOP_FN (op_rshift) |
3203
|
871 |
3525
|
872 OV_BINOP_FN_OP (op_lt, <) |
|
873 OV_BINOP_FN_OP (op_le, <=) |
|
874 OV_BINOP_FN_OP (op_eq, ==) |
|
875 OV_BINOP_FN_OP (op_ge, >=) |
|
876 OV_BINOP_FN_OP (op_gt, >) |
|
877 OV_BINOP_FN_OP (op_ne, !=) |
3203
|
878 |
3525
|
879 OV_BINOP_FN (op_el_mul) |
|
880 OV_BINOP_FN (op_el_div) |
|
881 OV_BINOP_FN (op_el_pow) |
|
882 OV_BINOP_FN (op_el_ldiv) |
|
883 OV_BINOP_FN (op_el_and) |
|
884 OV_BINOP_FN (op_el_or) |
3203
|
885 |
3525
|
886 OV_BINOP_FN (op_struct_ref) |
3203
|
887 |
3219
|
888 // T_ID is the type id of struct objects, set by register_type(). |
|
889 // T_NAME is the type name of struct objects. |
|
890 #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA \ |
|
891 public: \ |
|
892 int type_id (void) const { return t_id; } \ |
3523
|
893 std::string type_name (void) const { return t_name; } \ |
4612
|
894 std::string class_name (void) const { return c_name; } \ |
4252
|
895 static int static_type_id (void) { return t_id; } \ |
4901
|
896 static std::string static_type_name (void) { return t_name; } \ |
|
897 static std::string static_class_name (void) { return c_name; } \ |
4640
|
898 static void register_type (void); \ |
3219
|
899 \ |
|
900 private: \ |
4252
|
901 static int t_id; \ |
4612
|
902 static const std::string t_name; \ |
|
903 static const std::string c_name; |
3219
|
904 |
4612
|
905 #define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c) \ |
4252
|
906 int t::t_id (-1); \ |
4612
|
907 const std::string t::t_name (n); \ |
4640
|
908 const std::string t::c_name (c); \ |
|
909 void t::register_type (void) \ |
|
910 { \ |
|
911 t_id = octave_value_typeinfo::register_type (t::t_name, \ |
|
912 t::c_name, \ |
4645
|
913 octave_value (new t ())); \ |
4640
|
914 } |
3219
|
915 |
4455
|
916 // If TRUE, print a warning for assignments like |
2376
|
917 // |
|
918 // octave> A(1) = 3; A(2) = 5 |
|
919 // |
|
920 // for A already defined and a matrix type. |
4455
|
921 extern bool Vwarn_fortran_indexing; |
2376
|
922 |
4452
|
923 // Should we print a warning when converting `[97, 98, 99, "123"]' |
|
924 // to a character string? |
|
925 extern bool Vwarn_num_to_str; |
4257
|
926 |
4452
|
927 // If TRUE, warn for operations like |
2376
|
928 // |
|
929 // octave> 'abc' + 0 |
|
930 // 97 98 99 |
|
931 // |
4452
|
932 extern int Vwarn_str_to_num; |
2376
|
933 |
4451
|
934 // Should we warn about conversions from complex to real? |
|
935 extern int Vwarn_imag_to_real; |
2376
|
936 |
|
937 // If TRUE, print the name along with the value. |
|
938 extern bool Vprint_answer_id_name; |
|
939 |
|
940 // How many levels of structure elements should we print? |
|
941 extern int Vstruct_levels_to_print; |
|
942 |
|
943 // Allow divide by zero errors to be suppressed. |
|
944 extern bool Vwarn_divide_by_zero; |
|
945 |
4461
|
946 // If TRUE, print a warning when a matrix is resized by an indexed |
|
947 // assignment with indices outside the current bounds. |
|
948 extern bool Vwarn_resize_on_range_error; |
3195
|
949 |
2376
|
950 // Indentation level for structures. |
|
951 extern int struct_indent; |
|
952 |
|
953 extern void increment_struct_indent (void); |
|
954 extern void decrement_struct_indent (void); |
|
955 |
2880
|
956 // Indentation level for lists. |
|
957 extern int list_indent; |
|
958 |
|
959 extern void increment_list_indent (void); |
|
960 extern void decrement_list_indent (void); |
|
961 |
2376
|
962 extern void install_types (void); |
|
963 |
4946
|
964 // XXX FIXME XXX -- these trait classes probably belong somehwere else... |
|
965 |
|
966 template <typename T> |
|
967 class |
|
968 octave_type_traits |
|
969 { |
|
970 public: |
|
971 typedef T val_type; |
|
972 }; |
|
973 |
|
974 #define OCTAVE_TYPE_TRAIT(T, VAL_T) \ |
|
975 template <> \ |
|
976 class \ |
|
977 octave_type_traits<T> \ |
|
978 { \ |
|
979 public: \ |
|
980 typedef VAL_T val_type; \ |
|
981 } |
|
982 |
|
983 OCTAVE_TYPE_TRAIT (octave_int8, octave_int8::val_type); |
|
984 OCTAVE_TYPE_TRAIT (octave_uint8, octave_uint8::val_type); |
|
985 OCTAVE_TYPE_TRAIT (octave_int16, octave_int16::val_type); |
|
986 OCTAVE_TYPE_TRAIT (octave_uint16, octave_uint16::val_type); |
|
987 OCTAVE_TYPE_TRAIT (octave_int32, octave_int32::val_type); |
|
988 OCTAVE_TYPE_TRAIT (octave_uint32, octave_uint32::val_type); |
|
989 OCTAVE_TYPE_TRAIT (octave_int64, octave_int64::val_type); |
|
990 OCTAVE_TYPE_TRAIT (octave_uint64, octave_uint64::val_type); |
|
991 |
|
992 template <typename T> |
|
993 class octave_array_type_traits |
|
994 { |
|
995 public: |
|
996 typedef T element_type; |
|
997 }; |
|
998 |
|
999 #define OCTAVE_ARRAY_TYPE_TRAIT(T, ELT_T) \ |
|
1000 template <> \ |
|
1001 class \ |
|
1002 octave_array_type_traits<T> \ |
|
1003 { \ |
|
1004 public: \ |
|
1005 typedef ELT_T element_type; \ |
|
1006 } |
|
1007 |
|
1008 OCTAVE_ARRAY_TYPE_TRAIT (charNDArray, char); |
4970
|
1009 OCTAVE_ARRAY_TYPE_TRAIT (boolNDArray, bool); |
4946
|
1010 OCTAVE_ARRAY_TYPE_TRAIT (int8NDArray, octave_int8); |
|
1011 OCTAVE_ARRAY_TYPE_TRAIT (uint8NDArray, octave_uint8); |
|
1012 OCTAVE_ARRAY_TYPE_TRAIT (int16NDArray, octave_int16); |
|
1013 OCTAVE_ARRAY_TYPE_TRAIT (uint16NDArray, octave_uint16); |
|
1014 OCTAVE_ARRAY_TYPE_TRAIT (int32NDArray, octave_int32); |
|
1015 OCTAVE_ARRAY_TYPE_TRAIT (uint32NDArray, octave_uint32); |
|
1016 OCTAVE_ARRAY_TYPE_TRAIT (int64NDArray, octave_int64); |
|
1017 OCTAVE_ARRAY_TYPE_TRAIT (uint64NDArray, octave_uint64); |
|
1018 OCTAVE_ARRAY_TYPE_TRAIT (NDArray, double); |
|
1019 |
2376
|
1020 #endif |
|
1021 |
|
1022 /* |
|
1023 ;; Local Variables: *** |
|
1024 ;; mode: C++ *** |
|
1025 ;; End: *** |
|
1026 */ |