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