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