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