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 |
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, |
5885
|
304 bool resize_ok = false) |
3933
|
305 { return rep->do_index_op (idx, resize_ok); } |
|
306 |
5759
|
307 octave_value_list |
3544
|
308 do_multi_index_op (int nargout, const octave_value_list& idx); |
2974
|
309 |
5759
|
310 octave_value subsasgn (const std::string& type, |
4219
|
311 const std::list<octave_value_list>& idx, |
3933
|
312 const octave_value& rhs); |
2376
|
313 |
4247
|
314 octave_value assign (assign_op op, const std::string& type, |
4219
|
315 const std::list<octave_value_list>& idx, |
3933
|
316 const octave_value& rhs); |
2948
|
317 |
3933
|
318 const octave_value& assign (assign_op, const octave_value& rhs); |
2948
|
319 |
5759
|
320 idx_vector index_vector (void) const |
2376
|
321 { return rep->index_vector (); } |
|
322 |
|
323 // Size. |
|
324 |
5759
|
325 dim_vector dims (void) const |
4513
|
326 { return rep->dims (); } |
|
327 |
5759
|
328 octave_idx_type rows (void) const { return rep->rows (); } |
4563
|
329 |
5759
|
330 octave_idx_type columns (void) const { return rep->columns (); } |
3195
|
331 |
5275
|
332 octave_idx_type length (void) const; |
4554
|
333 |
5759
|
334 int ndims (void) const { return rep->ndims (); } |
4563
|
335 |
5164
|
336 bool all_zero_dims (void) const { return dims().all_zero (); } |
|
337 |
5759
|
338 octave_idx_type numel (void) const |
5080
|
339 { return rep->numel (); } |
4559
|
340 |
5759
|
341 octave_idx_type capacity (void) const |
5164
|
342 { return rep->capacity (); } |
|
343 |
5659
|
344 Matrix size (void) const; |
|
345 |
5759
|
346 size_t byte_size (void) const |
4791
|
347 { return rep->byte_size (); } |
|
348 |
5759
|
349 octave_idx_type nnz (void) const { return rep->nnz (); } |
5602
|
350 |
5759
|
351 octave_idx_type nzmax (void) const { return rep->nzmax (); } |
5604
|
352 |
5900
|
353 octave_idx_type nfields (void) const { return rep->nfields (); } |
|
354 |
5759
|
355 octave_value reshape (const dim_vector& dv) const |
4587
|
356 { return rep->reshape (dv); } |
4567
|
357 |
5759
|
358 octave_value permute (const Array<int>& vec, bool inv = false) const |
4593
|
359 { return rep->permute (vec, inv); } |
|
360 |
|
361 octave_value ipermute (const Array<int>& vec) const |
|
362 { return rep->permute (vec, true); } |
|
363 |
5759
|
364 octave_value resize (const dim_vector& dv, bool fill = false) const |
|
365 { return rep->resize (dv, fill);} |
4915
|
366 |
5785
|
367 MatrixType matrix_type (void) const |
|
368 { return rep->matrix_type (); } |
|
369 |
|
370 MatrixType matrix_type (const MatrixType& typ) const |
|
371 { return rep->matrix_type (typ); } |
|
372 |
2376
|
373 // Does this constant have a type? Both of these are provided since |
|
374 // it is sometimes more natural to write is_undefined() instead of |
|
375 // ! is_defined(). |
|
376 |
5759
|
377 bool is_defined (void) const |
2376
|
378 { return rep->is_defined (); } |
|
379 |
|
380 bool is_undefined (void) const |
|
381 { return ! is_defined (); } |
|
382 |
4559
|
383 bool is_empty (void) const |
5759
|
384 { return rep->is_empty (); } |
4559
|
385 |
5759
|
386 bool is_cell (void) const |
3351
|
387 { return rep->is_cell (); } |
|
388 |
6116
|
389 bool is_cellstr (void) const |
|
390 { return rep->is_cellstr (); } |
|
391 |
5759
|
392 bool is_real_scalar (void) const |
2376
|
393 { return rep->is_real_scalar (); } |
|
394 |
5759
|
395 bool is_real_matrix (void) const |
2376
|
396 { return rep->is_real_matrix (); } |
|
397 |
5759
|
398 bool is_real_nd_array (void) const |
4505
|
399 { return rep->is_real_nd_array (); } |
|
400 |
5759
|
401 bool is_complex_scalar (void) const |
2376
|
402 { return rep->is_complex_scalar (); } |
|
403 |
5759
|
404 bool is_complex_matrix (void) const |
2376
|
405 { return rep->is_complex_matrix (); } |
|
406 |
5881
|
407 bool is_bool_scalar (void) const |
|
408 { return rep->is_bool_scalar (); } |
|
409 |
5759
|
410 bool is_bool_matrix (void) const |
4587
|
411 { return rep->is_bool_matrix (); } |
|
412 |
5759
|
413 bool is_char_matrix (void) const |
2376
|
414 { return rep->is_char_matrix (); } |
|
415 |
5759
|
416 bool is_string (void) const |
2376
|
417 { return rep->is_string (); } |
|
418 |
5759
|
419 bool is_sq_string (void) const |
5279
|
420 { return rep->is_sq_string (); } |
|
421 |
5280
|
422 bool is_dq_string (void) const |
|
423 { return rep->is_string () && ! rep->is_sq_string (); } |
|
424 |
5759
|
425 bool is_range (void) const |
2376
|
426 { return rep->is_range (); } |
|
427 |
5759
|
428 bool is_map (void) const |
2376
|
429 { return rep->is_map (); } |
|
430 |
5759
|
431 bool is_streamoff (void) const |
4643
|
432 { return rep->is_streamoff (); } |
|
433 |
5759
|
434 bool is_cs_list (void) const |
3977
|
435 { return rep->is_cs_list (); } |
|
436 |
5759
|
437 bool is_list (void) const |
2880
|
438 { return rep->is_list (); } |
|
439 |
5759
|
440 bool is_magic_colon (void) const |
2376
|
441 { return rep->is_magic_colon (); } |
|
442 |
|
443 // Are any or all of the elements in this constant nonzero? |
|
444 |
5759
|
445 octave_value all (int dim = 0) const |
4015
|
446 { return rep->all (dim); } |
2376
|
447 |
5759
|
448 octave_value any (int dim = 0) const |
4015
|
449 { return rep->any (dim); } |
2376
|
450 |
5895
|
451 // Floating point types. |
|
452 |
|
453 bool is_double_type (void) const |
|
454 { return rep->is_double_type (); } |
|
455 |
|
456 bool is_single_type (void) const |
|
457 { return rep->is_single_type (); } |
|
458 |
|
459 // Integer types. |
|
460 |
|
461 bool is_int8_type (void) const |
|
462 { return rep->is_int8_type (); } |
|
463 |
|
464 bool is_int16_type (void) const |
|
465 { return rep->is_int16_type (); } |
|
466 |
|
467 bool is_int32_type (void) const |
|
468 { return rep->is_int32_type (); } |
|
469 |
|
470 bool is_int64_type (void) const |
|
471 { return rep->is_int64_type (); } |
|
472 |
|
473 bool is_uint8_type (void) const |
|
474 { return rep->is_uint8_type (); } |
|
475 |
|
476 bool is_uint16_type (void) const |
|
477 { return rep->is_uint16_type (); } |
|
478 |
|
479 bool is_uint32_type (void) const |
|
480 { return rep->is_uint32_type (); } |
|
481 |
|
482 bool is_uint64_type (void) const |
|
483 { return rep->is_uint64_type (); } |
|
484 |
2376
|
485 // Other type stuff. |
|
486 |
5759
|
487 bool is_bool_type (void) const |
3209
|
488 { return rep->is_bool_type (); } |
|
489 |
5759
|
490 bool is_real_type (void) const |
2376
|
491 { return rep->is_real_type (); } |
|
492 |
5759
|
493 bool is_complex_type (void) const |
2376
|
494 { return rep->is_complex_type (); } |
|
495 |
5759
|
496 bool is_scalar_type (void) const |
2376
|
497 { return rep->is_scalar_type (); } |
|
498 |
5759
|
499 bool is_matrix_type (void) const |
2376
|
500 { return rep->is_matrix_type (); } |
|
501 |
5759
|
502 bool is_numeric_type (void) const |
2376
|
503 { return rep->is_numeric_type (); } |
|
504 |
5759
|
505 bool is_sparse_type (void) const |
5631
|
506 { return rep->is_sparse_type (); } |
|
507 |
5759
|
508 bool valid_as_scalar_index (void) const |
2376
|
509 { return rep->valid_as_scalar_index (); } |
|
510 |
5759
|
511 bool valid_as_zero_index (void) const |
2376
|
512 { return rep->valid_as_zero_index (); } |
|
513 |
|
514 // Does this constant correspond to a truth value? |
|
515 |
5759
|
516 bool is_true (void) const |
2376
|
517 { return rep->is_true (); } |
|
518 |
|
519 // Are the dimensions of this constant zero by zero? |
|
520 |
5759
|
521 bool is_zero_by_zero (void) const |
|
522 { return (rows () == 0 && columns () == 0); } |
2376
|
523 |
5759
|
524 bool is_constant (void) const |
2974
|
525 { return rep->is_constant (); } |
|
526 |
5759
|
527 bool is_function_handle (void) const |
4654
|
528 { return rep->is_function_handle (); } |
|
529 |
5759
|
530 bool is_inline_function (void) const |
4954
|
531 { return rep->is_inline_function (); } |
|
532 |
5759
|
533 bool is_function (void) const |
2974
|
534 { return rep->is_function (); } |
2891
|
535 |
5759
|
536 bool is_builtin_function (void) const |
3325
|
537 { return rep->is_builtin_function (); } |
|
538 |
5759
|
539 bool is_dld_function (void) const |
3325
|
540 { return rep->is_dld_function (); } |
|
541 |
5864
|
542 bool is_mex_function (void) const |
|
543 { return rep->is_mex_function (); } |
|
544 |
2376
|
545 // Values. |
|
546 |
2891
|
547 octave_value eval (void) { return *this; } |
|
548 |
5759
|
549 short int |
4254
|
550 short_value (bool req_int = false, bool frc_str_conv = false) const |
|
551 { return rep->short_value (req_int, frc_str_conv); } |
|
552 |
5759
|
553 unsigned short int |
4254
|
554 ushort_value (bool req_int = false, bool frc_str_conv = false) const |
|
555 { return rep->ushort_value (req_int, frc_str_conv); } |
|
556 |
5759
|
557 int int_value (bool req_int = false, bool frc_str_conv = false) const |
3202
|
558 { return rep->int_value (req_int, frc_str_conv); } |
|
559 |
5759
|
560 unsigned int |
4254
|
561 uint_value (bool req_int = false, bool frc_str_conv = false) const |
|
562 { return rep->uint_value (req_int, frc_str_conv); } |
|
563 |
5759
|
564 int nint_value (bool frc_str_conv = false) const |
3202
|
565 { return rep->nint_value (frc_str_conv); } |
|
566 |
5759
|
567 long int |
4254
|
568 long_value (bool req_int = false, bool frc_str_conv = false) const |
|
569 { return rep->long_value (req_int, frc_str_conv); } |
|
570 |
5759
|
571 unsigned long int |
4254
|
572 ulong_value (bool req_int = false, bool frc_str_conv = false) const |
|
573 { return rep->ulong_value (req_int, frc_str_conv); } |
|
574 |
6133
|
575 octave_idx_type |
|
576 idx_type_value (bool req_int = false, bool frc_str_conv = false) const |
|
577 { |
|
578 #if SIZEOF_OCTAVE_IDX_TYPE == SIZEOF_LONG |
|
579 return long_value (req_int, frc_str_conv); |
|
580 #elif SIZEOF_OCTAVE_IDX_TYPE == SIZEOF_INT |
|
581 return int_value (req_int, frc_str_conv); |
|
582 #else |
|
583 #error "no octave_value extractor for octave_idx_type" |
|
584 #endif |
|
585 } |
|
586 |
5759
|
587 double double_value (bool frc_str_conv = false) const |
2376
|
588 { return rep->double_value (frc_str_conv); } |
|
589 |
5759
|
590 double scalar_value (bool frc_str_conv = false) const |
2916
|
591 { return rep->scalar_value (frc_str_conv); } |
|
592 |
5759
|
593 Cell cell_value (void) const; |
3351
|
594 |
5759
|
595 Matrix matrix_value (bool frc_str_conv = false) const |
2376
|
596 { return rep->matrix_value (frc_str_conv); } |
|
597 |
5759
|
598 NDArray array_value (bool frc_str_conv = false) const |
4550
|
599 { return rep->array_value (frc_str_conv); } |
4505
|
600 |
5759
|
601 Complex complex_value (bool frc_str_conv = false) const |
2376
|
602 { return rep->complex_value (frc_str_conv); } |
|
603 |
5759
|
604 ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const |
2376
|
605 { return rep->complex_matrix_value (frc_str_conv); } |
|
606 |
5759
|
607 ComplexNDArray complex_array_value (bool frc_str_conv = false) const |
4550
|
608 { return rep->complex_array_value (frc_str_conv); } |
|
609 |
5943
|
610 bool bool_value (bool warn = false) const |
|
611 { return rep->bool_value (warn); } |
4550
|
612 |
5943
|
613 boolMatrix bool_matrix_value (bool warn = false) const |
|
614 { return rep->bool_matrix_value (warn); } |
4550
|
615 |
5943
|
616 boolNDArray bool_array_value (bool warn = false) const |
|
617 { return rep->bool_array_value (warn); } |
4550
|
618 |
5759
|
619 charMatrix char_matrix_value (bool frc_str_conv = false) const |
2376
|
620 { return rep->char_matrix_value (frc_str_conv); } |
|
621 |
5759
|
622 charNDArray char_array_value (bool frc_str_conv = false) const |
4550
|
623 { return rep->char_array_value (frc_str_conv); } |
|
624 |
5759
|
625 SparseMatrix sparse_matrix_value (bool frc_str_conv = false) const |
|
626 { return rep->sparse_matrix_value (frc_str_conv); } |
5164
|
627 |
5759
|
628 SparseComplexMatrix sparse_complex_matrix_value (bool frc_str_conv = false) const |
|
629 { return rep->sparse_complex_matrix_value (frc_str_conv); } |
5164
|
630 |
5759
|
631 SparseBoolMatrix sparse_bool_matrix_value (bool frc_str_conv = false) const |
|
632 { return rep->sparse_bool_matrix_value (frc_str_conv); } |
5164
|
633 |
5759
|
634 octave_int8 int8_scalar_value (void) const |
4910
|
635 { return rep->int8_scalar_value (); } |
|
636 |
5759
|
637 octave_int16 int16_scalar_value (void) const |
4910
|
638 { return rep->int16_scalar_value (); } |
|
639 |
5759
|
640 octave_int32 int32_scalar_value (void) const |
4910
|
641 { return rep->int32_scalar_value (); } |
|
642 |
5759
|
643 octave_int64 int64_scalar_value (void) const |
4910
|
644 { return rep->int64_scalar_value (); } |
|
645 |
5759
|
646 octave_uint8 uint8_scalar_value (void) const |
4910
|
647 { return rep->uint8_scalar_value (); } |
|
648 |
5759
|
649 octave_uint16 uint16_scalar_value (void) const |
4910
|
650 { return rep->uint16_scalar_value (); } |
|
651 |
5759
|
652 octave_uint32 uint32_scalar_value (void) const |
4910
|
653 { return rep->uint32_scalar_value (); } |
|
654 |
5759
|
655 octave_uint64 uint64_scalar_value (void) const |
4910
|
656 { return rep->uint64_scalar_value (); } |
|
657 |
5759
|
658 int8NDArray int8_array_value (void) const |
4906
|
659 { return rep->int8_array_value (); } |
|
660 |
5759
|
661 int16NDArray int16_array_value (void) const |
4906
|
662 { return rep->int16_array_value (); } |
|
663 |
5759
|
664 int32NDArray int32_array_value (void) const |
4906
|
665 { return rep->int32_array_value (); } |
|
666 |
5759
|
667 int64NDArray int64_array_value (void) const |
4906
|
668 { return rep->int64_array_value (); } |
|
669 |
5759
|
670 uint8NDArray uint8_array_value (void) const |
4906
|
671 { return rep->uint8_array_value (); } |
|
672 |
5759
|
673 uint16NDArray uint16_array_value (void) const |
4906
|
674 { return rep->uint16_array_value (); } |
|
675 |
5759
|
676 uint32NDArray uint32_array_value (void) const |
4906
|
677 { return rep->uint32_array_value (); } |
|
678 |
5759
|
679 uint64NDArray uint64_array_value (void) const |
4906
|
680 { return rep->uint64_array_value (); } |
|
681 |
5759
|
682 string_vector all_strings (bool pad = false) const |
5715
|
683 { return rep->all_strings (pad); } |
2376
|
684 |
5759
|
685 std::string string_value (bool force = false) const |
4665
|
686 { return rep->string_value (force); } |
2376
|
687 |
5759
|
688 Range range_value (void) const |
2376
|
689 { return rep->range_value (); } |
|
690 |
5759
|
691 Octave_map map_value (void) const; |
2376
|
692 |
5759
|
693 string_vector map_keys (void) const |
3933
|
694 { return rep->map_keys (); } |
|
695 |
5759
|
696 std::streamoff streamoff_value (void) const; |
4645
|
697 |
5759
|
698 streamoff_array streamoff_array_value (void) const; |
4643
|
699 |
5759
|
700 octave_function *function_value (bool silent = false); |
2974
|
701 |
5759
|
702 octave_user_function *user_function_value (bool silent = false); |
4700
|
703 |
5759
|
704 octave_fcn_handle *fcn_handle_value (bool silent = false); |
4343
|
705 |
5759
|
706 octave_fcn_inline *fcn_inline_value (bool silent = false); |
4933
|
707 |
5759
|
708 octave_value_list list_value (void) const; |
2880
|
709 |
3419
|
710 ColumnVector column_vector_value (bool frc_str_conv = false, |
2376
|
711 bool frc_vec_conv = false) const; |
|
712 |
|
713 ComplexColumnVector |
3419
|
714 complex_column_vector_value (bool frc_str_conv = false, |
2376
|
715 bool frc_vec_conv = false) const; |
|
716 |
3419
|
717 RowVector row_vector_value (bool frc_str_conv = false, |
|
718 bool frc_vec_conv = false) const; |
|
719 |
|
720 ComplexRowVector |
|
721 complex_row_vector_value (bool frc_str_conv = false, |
|
722 bool frc_vec_conv = false) const; |
|
723 |
4044
|
724 Array<int> int_vector_value (bool req_int = false, |
|
725 bool frc_str_conv = false, |
|
726 bool frc_vec_conv = false) const; |
|
727 |
3419
|
728 Array<double> vector_value (bool frc_str_conv = false, |
|
729 bool frc_vec_conv = false) const; |
|
730 |
|
731 Array<Complex> complex_vector_value (bool frc_str_conv = false, |
|
732 bool frc_vec_conv = false) const; |
|
733 |
2376
|
734 // Conversions. These should probably be private. If a user of this |
|
735 // class wants a certain kind of constant, he should simply ask for |
|
736 // it, and we should convert it if possible. |
|
737 |
5279
|
738 octave_value convert_to_str (bool pad = false, bool force = false, |
5759
|
739 char type = '"') const |
|
740 { return rep->convert_to_str (pad, force, type); } |
4452
|
741 |
5759
|
742 octave_value |
5279
|
743 convert_to_str_internal (bool pad, bool force, char type) const |
|
744 { return rep->convert_to_str_internal (pad, force, type); } |
2376
|
745 |
5759
|
746 void convert_to_row_or_column_vector (void) |
2376
|
747 { rep->convert_to_row_or_column_vector (); } |
|
748 |
5759
|
749 bool print_as_scalar (void) const |
4604
|
750 { return rep->print_as_scalar (); } |
|
751 |
5759
|
752 void print (std::ostream& os, bool pr_as_read_syntax = false) const |
2466
|
753 { rep->print (os, pr_as_read_syntax); } |
2376
|
754 |
5759
|
755 void print_raw (std::ostream& os, |
4457
|
756 bool pr_as_read_syntax = false) const |
2903
|
757 { rep->print_raw (os, pr_as_read_syntax); } |
|
758 |
5759
|
759 bool print_name_tag (std::ostream& os, const std::string& name) const |
2903
|
760 { return rep->print_name_tag (os, name); } |
2376
|
761 |
3523
|
762 void print_with_name (std::ostream& os, const std::string& name, |
5759
|
763 bool print_padding = true) const |
|
764 { rep->print_with_name (os, name, print_padding); } |
2376
|
765 |
5759
|
766 int type_id (void) const { return rep->type_id (); } |
2376
|
767 |
5759
|
768 std::string type_name (void) const { return rep->type_name (); } |
|
769 |
|
770 std::string class_name (void) const { return rep->class_name (); } |
4612
|
771 |
3203
|
772 // Unary and binary operations. |
|
773 |
6109
|
774 friend OCTINTERP_API octave_value do_unary_op (unary_op op, |
3933
|
775 const octave_value& a); |
3203
|
776 |
3933
|
777 const octave_value& do_non_const_unary_op (unary_op op); |
|
778 |
|
779 void do_non_const_unary_op (unary_op op, const octave_value_list& idx); |
2376
|
780 |
4247
|
781 octave_value do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
782 const std::list<octave_value_list>& idx); |
3205
|
783 |
6109
|
784 friend OCTINTERP_API octave_value do_binary_op (binary_op op, |
3933
|
785 const octave_value& a, |
|
786 const octave_value& b); |
2376
|
787 |
6109
|
788 friend OCTINTERP_API octave_value do_cat_op (const octave_value& a, |
4915
|
789 const octave_value& b, |
|
790 const Array<int>& ra_idx); |
|
791 |
5759
|
792 const octave_base_value& get_rep (void) const { return *rep; } |
3301
|
793 |
5759
|
794 void print_info (std::ostream& os, |
3933
|
795 const std::string& prefix = std::string ()) const; |
|
796 |
5958
|
797 bool save_ascii (std::ostream& os, bool& infnan_warned) |
|
798 { return rep->save_ascii (os, infnan_warned); } |
4687
|
799 |
5759
|
800 bool load_ascii (std::istream& is) |
4687
|
801 { return rep->load_ascii (is); } |
|
802 |
5759
|
803 bool save_binary (std::ostream& os, bool& save_as_floats) |
4687
|
804 { return rep->save_binary (os, save_as_floats); } |
|
805 |
5759
|
806 bool load_binary (std::istream& is, bool swap, |
4687
|
807 oct_mach_info::float_format fmt) |
|
808 { return rep->load_binary (is, swap, fmt); } |
|
809 |
|
810 #if defined (HAVE_HDF5) |
5759
|
811 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) |
4687
|
812 { return rep->save_hdf5 (loc_id, name, save_as_floats); } |
|
813 |
5759
|
814 bool load_hdf5 (hid_t loc_id, const char *name, |
4687
|
815 bool have_h5giterate_bug) |
|
816 { return rep->load_hdf5 (loc_id, name, have_h5giterate_bug); } |
|
817 #endif |
|
818 |
5759
|
819 int write (octave_stream& os, int block_size, |
4944
|
820 oct_data_conv::data_type output_type, int skip, |
|
821 oct_mach_info::float_format flt_fmt) const; |
|
822 |
5759
|
823 octave_base_value *internal_rep (void) const { return rep; } |
4901
|
824 |
5900
|
825 // Unsafe. These functions exist to support the MEX interface. |
|
826 // You should not use them anywhere else. |
|
827 void *mex_get_data (void) const { return rep->mex_get_data (); } |
|
828 |
|
829 octave_idx_type *mex_get_ir (void) const { return rep->mex_get_ir (); } |
|
830 |
|
831 octave_idx_type *mex_get_jc (void) const { return rep->mex_get_jc (); } |
|
832 |
|
833 mxArray *as_mxArray (void) const { return rep->as_mxArray (); } |
|
834 |
2376
|
835 protected: |
|
836 |
5759
|
837 // The real representation. |
|
838 octave_base_value *rep; |
2413
|
839 |
3933
|
840 private: |
2903
|
841 |
3205
|
842 assign_op unary_op_to_assign_op (unary_op op); |
|
843 |
3204
|
844 binary_op op_eq_to_binary_op (assign_op op); |
|
845 |
3219
|
846 DECLARE_OCTAVE_ALLOCATOR |
2376
|
847 }; |
|
848 |
5508
|
849 // Publish externally used friend functions. |
|
850 |
6109
|
851 extern OCTINTERP_API octave_value |
5508
|
852 do_unary_op (octave_value::unary_op op, const octave_value& a); |
|
853 |
6109
|
854 extern OCTINTERP_API octave_value |
5508
|
855 do_binary_op (octave_value::binary_op op, |
|
856 const octave_value& a, const octave_value& b); |
|
857 |
3203
|
858 #define OV_UNOP_FN(name) \ |
|
859 inline octave_value \ |
|
860 name (const octave_value& a) \ |
|
861 { \ |
|
862 return do_unary_op (octave_value::name, a); \ |
|
863 } |
|
864 |
|
865 #define OV_UNOP_OP(name, op) \ |
|
866 inline octave_value \ |
|
867 operator op (const octave_value& a) \ |
|
868 { \ |
|
869 return name (a); \ |
|
870 } |
|
871 |
|
872 #define OV_UNOP_FN_OP(name, op) \ |
|
873 OV_UNOP_FN (name) \ |
|
874 OV_UNOP_OP (name, op) |
|
875 |
3525
|
876 OV_UNOP_FN_OP (op_not, !) |
|
877 OV_UNOP_FN_OP (op_uminus, -) |
3203
|
878 |
3525
|
879 OV_UNOP_FN (op_transpose) |
|
880 OV_UNOP_FN (op_hermitian) |
3203
|
881 |
|
882 // No simple way to define these for prefix and suffix ops? |
|
883 // |
|
884 // incr |
|
885 // decr |
|
886 |
|
887 #define OV_BINOP_FN(name) \ |
|
888 inline octave_value \ |
|
889 name (const octave_value& a1, const octave_value& a2) \ |
|
890 { \ |
|
891 return do_binary_op (octave_value::name, a1, a2); \ |
|
892 } |
|
893 |
|
894 #define OV_BINOP_OP(name, op) \ |
|
895 inline octave_value \ |
|
896 operator op (const octave_value& a1, const octave_value& a2) \ |
|
897 { \ |
|
898 return name (a1, a2); \ |
|
899 } |
|
900 |
|
901 #define OV_BINOP_FN_OP(name, op) \ |
|
902 OV_BINOP_FN (name) \ |
|
903 OV_BINOP_OP (name, op) |
|
904 |
3525
|
905 OV_BINOP_FN_OP (op_add, +) |
|
906 OV_BINOP_FN_OP (op_sub, -) |
|
907 OV_BINOP_FN_OP (op_mul, *) |
|
908 OV_BINOP_FN_OP (op_div, /) |
3203
|
909 |
3525
|
910 OV_BINOP_FN (op_pow) |
|
911 OV_BINOP_FN (op_ldiv) |
|
912 OV_BINOP_FN (op_lshift) |
|
913 OV_BINOP_FN (op_rshift) |
3203
|
914 |
3525
|
915 OV_BINOP_FN_OP (op_lt, <) |
|
916 OV_BINOP_FN_OP (op_le, <=) |
|
917 OV_BINOP_FN_OP (op_eq, ==) |
|
918 OV_BINOP_FN_OP (op_ge, >=) |
|
919 OV_BINOP_FN_OP (op_gt, >) |
|
920 OV_BINOP_FN_OP (op_ne, !=) |
3203
|
921 |
3525
|
922 OV_BINOP_FN (op_el_mul) |
|
923 OV_BINOP_FN (op_el_div) |
|
924 OV_BINOP_FN (op_el_pow) |
|
925 OV_BINOP_FN (op_el_ldiv) |
|
926 OV_BINOP_FN (op_el_and) |
|
927 OV_BINOP_FN (op_el_or) |
3203
|
928 |
3525
|
929 OV_BINOP_FN (op_struct_ref) |
3203
|
930 |
6109
|
931 extern OCTINTERP_API void install_types (void); |
2376
|
932 |
5775
|
933 // FIXME -- these trait classes probably belong somehwere else... |
4946
|
934 |
|
935 template <typename T> |
|
936 class |
|
937 octave_type_traits |
|
938 { |
|
939 public: |
|
940 typedef T val_type; |
|
941 }; |
|
942 |
|
943 #define OCTAVE_TYPE_TRAIT(T, VAL_T) \ |
|
944 template <> \ |
|
945 class \ |
|
946 octave_type_traits<T> \ |
|
947 { \ |
|
948 public: \ |
|
949 typedef VAL_T val_type; \ |
|
950 } |
|
951 |
|
952 OCTAVE_TYPE_TRAIT (octave_int8, octave_int8::val_type); |
|
953 OCTAVE_TYPE_TRAIT (octave_uint8, octave_uint8::val_type); |
|
954 OCTAVE_TYPE_TRAIT (octave_int16, octave_int16::val_type); |
|
955 OCTAVE_TYPE_TRAIT (octave_uint16, octave_uint16::val_type); |
|
956 OCTAVE_TYPE_TRAIT (octave_int32, octave_int32::val_type); |
|
957 OCTAVE_TYPE_TRAIT (octave_uint32, octave_uint32::val_type); |
|
958 OCTAVE_TYPE_TRAIT (octave_int64, octave_int64::val_type); |
|
959 OCTAVE_TYPE_TRAIT (octave_uint64, octave_uint64::val_type); |
|
960 |
|
961 template <typename T> |
|
962 class octave_array_type_traits |
|
963 { |
|
964 public: |
|
965 typedef T element_type; |
|
966 }; |
|
967 |
|
968 #define OCTAVE_ARRAY_TYPE_TRAIT(T, ELT_T) \ |
|
969 template <> \ |
|
970 class \ |
|
971 octave_array_type_traits<T> \ |
|
972 { \ |
|
973 public: \ |
|
974 typedef ELT_T element_type; \ |
|
975 } |
|
976 |
|
977 OCTAVE_ARRAY_TYPE_TRAIT (charNDArray, char); |
4970
|
978 OCTAVE_ARRAY_TYPE_TRAIT (boolNDArray, bool); |
4946
|
979 OCTAVE_ARRAY_TYPE_TRAIT (int8NDArray, octave_int8); |
|
980 OCTAVE_ARRAY_TYPE_TRAIT (uint8NDArray, octave_uint8); |
|
981 OCTAVE_ARRAY_TYPE_TRAIT (int16NDArray, octave_int16); |
|
982 OCTAVE_ARRAY_TYPE_TRAIT (uint16NDArray, octave_uint16); |
|
983 OCTAVE_ARRAY_TYPE_TRAIT (int32NDArray, octave_int32); |
|
984 OCTAVE_ARRAY_TYPE_TRAIT (uint32NDArray, octave_uint32); |
|
985 OCTAVE_ARRAY_TYPE_TRAIT (int64NDArray, octave_int64); |
|
986 OCTAVE_ARRAY_TYPE_TRAIT (uint64NDArray, octave_uint64); |
|
987 OCTAVE_ARRAY_TYPE_TRAIT (NDArray, double); |
|
988 |
5759
|
989 // This will eventually go away, but for now it can be used to |
|
990 // simplify the transition to the new octave_value class hierarchy, |
|
991 // which uses octave_base_value instead of octave_value for the type |
|
992 // of octave_value::rep. |
|
993 #define OV_REP_TYPE octave_base_value |
|
994 |
2376
|
995 #endif |
|
996 |
|
997 /* |
|
998 ;; Local Variables: *** |
|
999 ;; mode: C++ *** |
|
1000 ;; End: *** |
|
1001 */ |